Closed brownieboy closed 7 years ago
My guess is that this is because the postgres role doesn't have a password. You may also want to check your pg_hba.conf to make sure login is enabled.
This may help: https://stackoverflow.com/a/7696398
Thanks for the response.
My pg_hba.conf has the following entries, which are, I think, what the SO post is referring to:
local all postgres peer
local all all peer
It seems to be connecting to the db all right though. Before it throws the error that I posted, the postgraphql --schema forum_example
commands the the connection info below:
PostGraphQL server listening on port 5000 🚀
‣ Connected to Postgres instance postgres://localhost:5432 ‣ Introspected Postgres schema(s) forum_example ‣ GraphQL endpoint served at http://localhost:5000/graphql ‣ GraphiQL endpoint served at http://localhost:5000/graphiql
error: password authentication failed for user "mikey"
Do I need to switch to the postgres ID first? I've setup my test database under my mikey ID, following the Digital Ocean tutorial linked above (although their use is called "sammy").
I believe Postgres is trying to login with your current user. The username matches, but since there is no password in Postgres the authentication fails. Did you try setting a password for the Postgres role? If not, give it a shot.
ALTER USER mikey WITH PASSWORD 'password';
Thank you again, @sjensen85.
I'm making some progress now. I changed the mikey ID's password, as per your advice. So postgraphql -c "postgres://localhost:5432/mikey"
still fails with the password authentication error, but postgraphql -c "postgres://mikey:password@localhost:5432/mikey"
seems to connect okay.
My postgraphql --schema forum_example
still fails with that authentication error though. How do I pass it the postgres password for the mikey ID?
Update Doh. I just had to amalgamate the two calls, like so:
postgraphql --schema forum_example -c "postgres://mikey:password@localhost:5432/mikey"
It now appears to be connected, and is showing me three asterisks. On to the next step!
Hey just for anyone in the future getting this error on windows, note that if you don't use double quotes around the db url it doesn't recognise it and tried to log you in via your username.
npx postgraphile -c "postgres://username:pass@localhost:5432/db" --watch --enhance-graphiql --dynamic-json
Hmmm scratch this - it's now failing again. Not sure what's different (might be node - I'm on version 15.1.0)
c:\Users\karl\one-off-data-scripts\graphile-migration>npx postgraphile -c "postgres://postgres:password@localhost:5432/prices_graphile" --watch --enhance-graphiql --dynamic-json
PostGraphile v4.9.2 server listening on port 5000 🚀
‣ GraphQL API: http://localhost:5000/graphql
‣ GraphiQL GUI/IDE: http://localhost:5000/graphiql
‣ Postgres connection: postgres:///postgres:password@localhost:5432/prices_graphile (watching)
‣ Postgres schema(s): public
‣ Documentation: https://graphile.org/postgraphile/introduction/
‣ Join Dovetail in supporting PostGraphile development: https://graphile.org/sponsor/
* * *
A serious error occurred when building the initial schema. Exiting because `retryOnInitFail` is not set. Error details:
error: password authentication failed for user "karlp"
at Parser.parseErrorMessage (C:\Users\karlp\AppData\Local\npm-cache\_npx\1b80421a9ae535da\node_modules\pg-protocol\dist\parser.js:278:15)
at Parser.handlePacket (C:\Users\karlp\AppData\Local\npm-cache\_npx\1b80421a9ae535da\node_modules\pg-protocol\dist\parser.js:126:29)
at Parser.parse (C:\Users\karlp\AppData\Local\npm-cache\_npx\1b80421a9ae535da\node_modules\pg-protocol\dist\parser.js:39:38)
at Socket.<anonymous> (C:\Users\karlp\AppData\Local\npm-cache\_npx\1b80421a9ae535da\node_modules\pg-protocol\dist\index.js:10:42)
at Socket.emit (node:events:327:20)
at addChunk (node:internal/streams/readable:304:12)
at readableAddChunk (node:internal/streams/readable:279:9)
at Socket.Readable.push (node:internal/streams/readable:218:10)
at TCP.onStreamRead (node:internal/stream_base_commons:192:23)
npm ERR! code 34
npm ERR! path c:\Users\karl\one-off-data-scripts\graphile-migration
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c ""postgraphile" "-c" "postgres:\postgres:password@localhost:5432\prices_graphile" "--watch" "--enhance-graphiql" "--dynamic-json""
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\karlp\AppData\Local\npm-cache\_logs\2020-11-24T09_42_34_723Z-debug.log
Yup - bizarrely if I switch to node 14.15.0
(I'm using windows nvm https://github.com/coreybutler/nvm-windows) it works!
c:\Users\karl\one-off-data-scripts\graphile-migration>nvm use 14.15.0
Now using node v14.15.0 (64-bit)
c:\Users\karl\one-off-data-scripts\graphile-migration>npx postgraphile -c "postgres://postgres:password@localhost:5432/prices_graphile" --watch --enhance-graphiql --dynamic-json
npx: installed 125 in 16.496s
PostGraphile v4.9.2 server listening on port 5000 🚀
‣ GraphQL API: http://localhost:5000/graphql
‣ GraphiQL GUI/IDE: http://localhost:5000/graphiql
‣ Postgres connection: postgres://postgres:[SECRET]@localhost/prices_graphile (watching)
‣ Postgres schema(s): public
‣ Documentation: https://graphile.org/postgraphile/introduction/
‣ Join Mark Rapoza in supporting PostGraphile development: https://graphile.org/sponsor/
* * *
Subtle, but in the first one:
‣ Postgres connection: postgres:///postgres:password@localhost:5432/prices_graphile (watching)
In the second one:
‣ Postgres connection: postgres://postgres:[SECRET]@localhost/prices_graphile (watching)
Note the extra slash in the first one? Also the fact that it says "karlp" in the error but you're using "postgres" as the username indicates that the connection string is not being parsed correctly (that and the password was not masked out); at the moment it thinks that your database name is postgres:password@localhost:5432
and it's connecting with default username, password, hostname, etc.
Ah thanks @benjie I didn't catch that!
I'm trying to follow the example at https://github.com/postgraphql/postgraphql/tree/master/examples/forum. I followed these instructions to get postgresql installed on a Linux VM: https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-16-04.
My db and my user/role are both called "mikey". When I setup the mikey id within postgresql, I did not specify a password. My OS-level Linux ID is also called mikey, and of course has a password.
At the
postgraphql --schema forum_example
step, the example code is throwing the following error:Did I miss a step somewhere?
Update: as per the tutorial link, I am running on Ubuntu Server 16.04.