0

I'm trying to get postgresql 13.x running on AlmaLinux. The package manage shows v13.x is available and I install postgresql-server:

sudo yum install -y postgresql-server postgresql-contrib

I then try to initialize the first db:

sudo postgresql-setup --initdb

Because I had to redo some stuff, this directory is not empty, then I run into permissions issues. I've tried setting ownership to my account, but it doesn't work either:

ERROR: Data directory /var/lib/pgsql/data is not empty!
ERROR: Initializing database failed, possibly see /var/lib/pgsql/initdb_postgresql.log
[Wed Jun 29 18:31:40 rich@server1 /var/lib] cd pgsql
-bash: cd: pgsql: Permission denied
[Wed Jun 29 18:31:50 rich@server1 /var/lib] sudo ls -al pgsql/data
total 60
drwx------. 20 postgres postgres  4096 May 26 11:53 .
drwx------.  4 postgres postgres    54 Jun 29 18:27 ..
drwx------.  5 rich     rich        41 Jun 29 11:01 base
-rw-------.  1 rich     rich        30 Jun 29 15:58 current_logfiles
drwx------.  2 rich     rich      4096 Jun 29 11:01 global
drwx------.  2 rich     rich        32 Jun 29 11:02 log
drwx------.  2 rich     rich         6 Jun 29 11:01 pg_commit_ts
drwx------.  2 rich     rich         6 Jun 29 11:01 pg_dynshmem
-rw-------.  1 rich     rich      4760 Jun 29 11:01 pg_hba.conf
-rw-------.  1 rich     rich      1636 Jun 29 11:01 pg_ident.conf
drwx------.  4 rich     rich        68 Jun 29 11:01 pg_logical
drwx------.  4 rich     rich        36 Jun 29 11:01 pg_multixact
drwx------.  2 rich     rich         6 Jun 29 11:01 pg_notify
drwx------.  2 rich     rich         6 Jun 29 11:01 pg_replslot
drwx------.  2 rich     rich         6 Jun 29 11:01 pg_serial
drwx------.  2 rich     rich         6 Jun 29 11:01 pg_snapshots
drwx------.  2 rich     rich         6 Jun 29 11:01 pg_stat
drwx------.  2 rich     rich         6 Jun 29 11:01 pg_stat_tmp
drwx------.  2 rich     rich        18 Jun 29 11:01 pg_subtrans
drwx------.  2 rich     rich         6 Jun 29 11:01 pg_tblspc
drwx------.  2 rich     rich         6 Jun 29 11:01 pg_twophase
-rw-------.  1 rich     rich         3 Jun 29 11:01 PG_VERSION
drwx------.  3 rich     rich        60 Jun 29 11:01 pg_wal
drwx------.  2 rich     rich        18 Jun 29 11:01 pg_xact
-rw-------.  1 rich     rich        88 Jun 29 11:01 postgresql.auto.conf
-rw-------.  1 rich     rich     28098 Jun 29 11:01 postgresql.conf

So now I'm caught between initializing a new database and getting past permissions. Anybody know how I can get this running?

EDIT: further info

Here is the report behind the permissions issue:

░░ A start job for unit postgresql.service has begun execution.
░░
░░ The job identifier is 2450.
Jun 29 21:28:58 server1.project33.ca postgresql-check-db-dir[2593]: cat: /var/lib/pgsql/data/PG_VERSION: Permission denied
Jun 29 21:28:58 server1.project33.ca postgresql-check-db-dir[2592]: An old version '' of the database format was found.
Jun 29 21:28:58 server1.project33.ca postgresql-check-db-dir[2592]: You need to dump and reload before using PostgreSQL 13.7.
Jun 29 21:28:58 server1.project33.ca postgresql-check-db-dir[2592]: See /usr/share/doc/postgresql/README.rpm-dist for more information.
Jun 29 21:28:58 server1.project33.ca systemd[1]: postgresql.service: Control process exited, code=exited, status=1/FAILURE
░░ Subject: Unit process exited
░░ Defined-By: systemd
░░ Support: https://access.redhat.com/support
░░
░░ An ExecStartPre= process belonging to unit postgresql.service has exited.
░░
░░ The process' exit code is 'exited' and its exit status is 1.
Jun 29 21:28:58 server1.project33.ca systemd[1]: postgresql.service: Failed with result 'exit-code'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: https://access.redhat.com/support
░░
░░ The unit postgresql.service has entered the 'failed' state with result 'exit-code'.
Jun 29 21:28:58 server1.project33.ca systemd[1]: Failed to start PostgreSQL database server.
░░ Subject: A start job for unit postgresql.service has failed
░░ Defined-By: systemd
░░ Support: https://access.redhat.com/support
░░
░░ A start job for unit postgresql.service has finished with a failure.
░░
░░ The job identifier is 2450 and the job result is failed.
Rich_F
  • 1,830
  • 3
  • 24
  • 45

1 Answers1

0

Solved: sudo postgresql-setup --initdb

Permissions issue with /var/lib/pgsql/data being owned by postgresql:postgresql.

Then log in using the postgres user, start with:

createdb `whoami`

...which creates the postgres database. While inside, you can create roles and databases, or exit to your user and use the createdb syntax again.

Rich_F
  • 1,830
  • 3
  • 24
  • 45