I have build postgres from source and have started it correctly. But every time I reboot my system and write psql, it gives the following error:
And so I have to start it like this:
bin/pg_ctl -D demo -l logfile start
And then it works until I reboot again
I am using Ubuntu 22. Thank you for any hints.
7
Answers
You need to use
pg_ctl stop
before you reboot because if you are rebooting without using it, the database doesn’t exit correctly. Also if you are rebooting, the connection to the server closes so it is normal that you need to usebin/pg_ctl -D demo -l logfile start
to start the database again.postgresql is a service just add it as start on boot this varies depending on the O.S. here is for Ubuntu https://askubuntu.com/questions/539187/how-to-make-postgres-start-automatically-on-boot it may give you problemms with credentials but that’s just a matter of configuration
To start the service, you can use:
sudo service postgresql start
To check if the service is enabled for startup on ubuntu (systemd system manager):
To enable the service to start on boot every time:
Checking again:
Have you installed your Postgres from source code and set path?
source AGE official
I was facing the same issue. I have to use bin/pg_ctl.
set you path.
you can check this blog as well: source link here
Rebooting stops the server which is the reason you are facing this problem.
You can manually stop the server which is a better way to close the connection as it eliminates the chances for abnormal behaviour. Thats why you have to start the server again before running psql.
One more thing, I don’t know how its working for you but I have to start psql like this "bin/psql ‘dbname’ ". Try running like this.
If you don’t use the
bin/pg_ctl -D demo stop
your database will not exit in the right way. You can also make a file to start the psql everytime you power on your Ubuntu. By adding the following command in a service file.After this you have to reload the daemon:
start the service:
and finally enable the service to start on boot:
If you are unable to solve it by the answers given above, try setting the PostgreSQL service start automatically on reboot.
You can achieve this by a tool called "systemctl".
You can refer here & to the official documentation. This link might also help.