0

I'm a newbie to PostgreSQL and I'm trying to create a user/role on Postgres 11 (running on CentOS7) which is named (e.g.) "json_docs_admin" (same for password) that I can use under the OS user (e.g.) "app_user" to connect locally to the DB.

I have tried connecting to Postgres using "postgres" user and the command "psql -d template1" and ran the following commands:

template1=# create role json_docs_admin with login password 'json_docs_admin';
CREATE ROLE
template1=# create database json_docs owner=json_docs_admin;
CREATE DATABASE
template1=# GRANT ALL PRIVILEGES ON DATABASE json_docs TO json_docs_admin;
GRANT

I have changed the /var/lib/pgsql/11/data/pg_hba.conf so that local connections can be established on the server, and I've restarted the postgresql service.

Then, back under "app_user" user, when I try to connect to the database, I get the following errors:

$psql -d json_docs -U json_docs_admin
Password for user json_docs_admin: 
psql: FATAL:  database "json_docs" does not exist

Could anybody let me know what am I doing wrong? Thanks.

Babak Tourani
  • 419
  • 2
  • 6
  • 18
  • Works for me: https://i.imgur.com/IUgMn1I.png Is it possible you were connected to a different server when you ran the `create database` statement? –  Mar 31 '19 at 20:13
  • Not really, there are no other servers. It's a single node cloud deployment (on CentOS 7) and the connection will be made locally to the DB. so no remote connections/DBs are involved. Thanks for checking. – Babak Tourani Mar 31 '19 at 22:33
  • It can also be a different PostgreSQL cluster (different port) on the same machine. Or you ran `DROP DATABASE` in between. – Laurenz Albe Apr 01 '19 at 02:16
  • Could you connect with postgres user (`sudo -u postgres psql`) and try `\l` to see if your database "json_docs" exists ? – Arkhena Apr 03 '19 at 06:06

0 Answers0