You are not logged in.
I had installed the postgresql package (16) a while ago and initialized the database cluster with initdb. I vaguely remember that I had used some directory but forgot the location so I initialized again to another directory.
> mkdir ~/PostgreSQL
> initdb -D ~/PostgreSQL
The files belonging to this database system will be owned by user "Andy".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
creating directory /home/a/PostgreSQL ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... UTC
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
initdb: warning: enabling "trust" authentication for local connections
initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
pg_ctl -D /home/a/PostgreSQL -l logfile start
> pg_ctl -D /home/a/PostgreSQL -l logfile start
waiting for server to start.... stopped waiting
pg_ctl: could not start server
Examine the log output.
> cat logfile
2024-07-31 11:13:52.364 UTC [180588] LOG: starting PostgreSQL 16.3 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 14.1.1 20240720, 64-bit
2024-07-31 11:13:52.365 UTC [180588] LOG: listening on IPv6 address "::1", port 5432
2024-07-31 11:13:52.365 UTC [180588] LOG: listening on IPv4 address "127.0.0.1", port 5432
2024-07-31 11:13:52.365 UTC [180588] LOG: listening on IPv4 address "127.0.1.1", port 5432
2024-07-31 11:13:52.366 UTC [180588] FATAL: could not create lock file "/run/postgresql/.s.PGSQL.5432.lock": No such file or directory
2024-07-31 11:13:52.367 UTC [180588] LOG: database system is shut down
> sudo systemctl start postgresql.service
Job for postgresql.service failed because the control process exited with error code.
See "systemctl status postgresql.service" and "journalctl -xeu postgresql.service" for details.
> sudo systemctl status postgresql.service
× postgresql.service - PostgreSQL database server
Loaded: loaded (/usr/lib/systemd/system/postgresql.service; disabled; preset: disabled)
Active: failed (Result: exit-code) since Wed 2024-07-31 11:17:20 UTC; 10s ago
Invocation: 76a25b69339644b5b5d79f055ba0ee2d
Docs: man:postgres(1)
Process: 181765 ExecStartPre=/usr/bin/postgresql-check-db-dir ${PGROOT}/data (code=exited, status=1/FAILURE)
Mem peak: 1.8M
CPU: 25ms
> echo ${PGROOT}
> sudo journalctl -xeu postgresql.service
Jul 31 11:17:20 localhost systemd[1]: postgresql.service: Failed with result 'exit-code'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░
░░ The unit postgresql.service has entered the 'failed' state with result 'exit-code'.
Jul 31 11:17:20 localhost systemd[1]: Failed to start PostgreSQL database server.
░░ Subject: A start job for unit postgresql.service has failed
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░
░░ A start job for unit postgresql.service has finished with a failure.
░░
░░ The job identifier is 10677 and the job result is failed.
Jul 31 11:17:46 localhost systemd[1]: Starting PostgreSQL database server...
░░ Subject: A start job for unit postgresql.service has begun execution
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░
░░ A start job for unit postgresql.service has begun execution.
░░
░░ The job identifier is 10830.
Jul 31 11:17:46 localhost postgres[181854]: "/var/lib/postgres/data" is missing or empty. Use a command like
Jul 31 11:17:46 localhost postgres[181854]: su -l postgres -c "initdb --locale=C.UTF-8 --encoding=UTF8 -D '/var/lib/p>
Jul 31 11:17:46 localhost postgres[181854]: with relevant options, to initialize the database cluster.
Jul 31 11:17:46 localhost systemd[1]: postgresql.service: Control process exited, code=exited, status=1/FAILURE
░░ Subject: Unit process exited
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░
░░ An ExecStartPre= process belonging to unit postgresql.service has exited.
░░
░░ The process' exit code is 'exited' and its exit status is 1.
Jul 31 11:17:46 localhost systemd[1]: postgresql.service: Failed with result 'exit-code'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░
░░ The unit postgresql.service has entered the 'failed' state with result 'exit-code'.
Jul 31 11:17:46 localhost systemd[1]: Failed to start PostgreSQL database server.
░░ Subject: A start job for unit postgresql.service has failed
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░
░░ A start job for unit postgresql.service has finished with a failure.
░░
░░ The job identifier is 10830 and the job result is failed.
Am I erroring out because I didn't properly clean up my previous database, or because the database is not in the default location?
Last edited by obituary749 (2024-07-31 12:16:10)
Offline
Whoever thought that [postgres]$ was a good way to indicate that the command must be run as the postgres user was way too deep into the rabbit hole.
EDIT: Okay, the wiki says "You can now switch to the postgres user using a privilege elevation program.", so the notation was fine and neither you nor I did properly read the article.
Last edited by Awebb (2024-07-31 11:56:18)
Offline
Whoever thought that [postgres]$ was a good way to indicate that the command must be run as the postgres user was way too deep into the rabbit hole.
EDIT: Okay, the wiki says "You can now switch to the postgres user using a privilege elevation program.", so the notation was fine and neither you nor I did properly read the article.
I thought it meant that I needed to switch to the user that will be using PostgreSQL. Turns out I need to switch to the user "postgres". Got it.
Offline