Most tutorials were installing both postgresql and postgresql-server:

$ sudo yum install postgresql postgresql-server

  postgresql.x86_64 0:9.2.24-1.amzn2.0.1                         
  postgresql-server.x86_64 0:9.2.24-1.amzn2.0.1                        

Dependency Installed:
  postgresql-libs.x86_64 0:9.2.24-1.amzn2.0.1                                                                                          

The programs are installed here:

$ which psql

$ which postgres

At this point, most tutorials go into initdb and pg_ctl <path> start

$ cd '/usr/lib'

$ service postgresql initdb
Hint: the preferred way to do this is now "postgresql-setup initdb"

$ sudo postgresql-setup initdb
[sudo] password for CORP\layne.sadler: 
Initializing database ... OK

$ systemctl enable postgresql
Created symlink from /etc/systemd/system/multi-user.target.wants/postgresql.service to usr/lib/systemd/system/postgresql.service.

$ systemctl start postgresql
[18:47:32]  /usr/bin ☯  systemctl status postgresql
● postgresql.service - PostgreSQL database server
   Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2020-03-05 18:47:32 EST; 7s ago
  Process: 25559 ExecStart=/usr/bin/pg_ctl start -D ${PGDATA} -s -o -p ${PGPORT} -w -t 300 (code=exited, status=0/SUCCESS)
  Process: 25553 ExecStartPre=/usr/bin/postgresql-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
 Main PID: 25562 (postgres)
   CGroup: /system.slice/postgresql.service
           ├─25562 /usr/bin/postgres -D /var/lib/pgsql/data -p 5432
           ├─25564 postgres: logger process   
           ├─25566 postgres: checkpointer process   
           ├─25567 postgres: writer process   
           ├─25568 postgres: wal writer process   
           ├─25569 postgres: autovacuum launcher process   
           └─25570 postgres: stats collector process

$ passwd postgres  

note: /usr/bin/postgres -D /var/lib/pgsql/data -p 5432


postgres does not know where to find the server configuration file.
You must specify the --config-file or -D invocation option or set the PGDATA environment variable.

$ psql
psql: FATAL:  role "CORP\layne.sadler" does not exist

$ sudo pg_ctl -D postgresql-setup initdb
pg_ctl: cannot be run as root
Please log in (using, e.g., "su") as the (unprivileged) user that will
own the server process.

# can't seem to login as su despite other sudo commands working


  • The OS claims to be rhel fedora centos but doesn't have the rhel-release libraries.
  • It seems like epel-release and dnf are blocked from install.
  • ^^^ postgres installation instructions want the above tools.
  • 3
    Solutions go into the answer box at the bottom of the page. It's perfectly fine to self-answer your own questions. Doing so would allow you to accept the answer (after a slight delay), which would mark the issue as resolved. I will remove the "SOLVED" tagging from the title, and I suggest that you move the solution into a proper answer.
    – Kusalananda
    Mar 5, 2020 at 23:53
  • 3
    According to your output, the postgresql server is running and the database is already initialized (/var/lib/pgsql/data). To connect to postgresql, try this as root: su -c "psql" postgres. This will invoke the psql client using the user postgres (IIRC, that is the default user those packages would be using). Mar 6, 2020 at 19:53
  • @Kermit - is this problem still alive? Without further feedback from you this can't be conclusively answered - as it stands it's very much a dog's breakfast. We'd need to for instance see your postgres.conf and your pg_hba.conf ..
    – tink
    Sep 6, 2022 at 1:39
  • @tink i changed projects a long time ago
    – Kermit
    Sep 7, 2022 at 11:41
  • @Kermit - as there's never been an accepted answer - would you mind deleting your question, then? As it stands it's just a festering boil that community will percolate up for re-inspection every so often ... which is how it got my attention.
    – tink
    Sep 7, 2022 at 19:36

1 Answer 1


CentOS (Community ENTerprise Operating System) is a community (re)build of RHEL (Red Hat Enterprise Linux), with changed branding and some other details. It strives at being binary fully compatible, down to bug-for-bug. It doesn't have access to the RHEL package repositories, it uses their own. EPEL (Extra Packages for Enterprise Linux) is a Fedora project that offers packages for RHEL/CentOS that RHEL doesn't carry.

I don't know where the "dnf is blocked from install" comes from. Note that in RHEL/CentOS dnf is relatively new (I believe an alternative starting with version 7), perhaps only the (legacy) yum is available? You could try yum install dnf if you need it. Depending on your exact version of CentOS, it might not be there at all.

The last error message you cite is quite clear: Postgres can't find/read it's configuration. Check carefully that the setup is done correctly. A wrong file name somewhere can derail everything.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .