-1

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:

enter image description here

And so I have to start it like this:

bin/pg_ctl -D demo -l logfile start

enter image description here

And then it works until I reboot again

enter image description here

I am using Ubuntu 22. Thank you for any hints.

han
  • 74
  • 7
  • 2
    By building from source, you have taken on this responsibility for yourself. This is primarily a question about Linux start up, so not really a programming question, nor superficially a PostgreSQL one. But see contrib/start-scripts/linux in the source code directory. – jjanes Apr 04 '23 at 15:05
  • 1
    Please post text as text, not as screenshots of text – DavidW Apr 22 '23 at 08:21

7 Answers7

0

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 use bin/pg_ctl -D demo -l logfile start to start the database again.

0

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

0

Have you installed your Postgres from source code and set path?

make PG_CONFIG=/path/to/postgres/bin/pg_config install

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

Venkataraman R
  • 12,181
  • 2
  • 31
  • 58
0

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.

0

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.

ExecStart=/path/to/bin/pg_ctl -D demo -l logfile start

After this you have to reload the daemon:

sudo systemctl daemon-reload

start the service:

sudo systemctl start my_service

and finally enable the service to start on boot:

sudo systemctl enable my_service
0

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.

Huzaifa
  • 484
  • 4
  • 8
-1

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):

sudo systemctl list-unit-files --type=service | grep postgres
UNIT FILE                                  STATE           VENDOR PRESET
postgresql.service                         disabled        enabled
postgresql@.service                        indirect        enabled

To enable the service to start on boot every time:

ahmar@raze:~$ sudo systemctl enable postgresql.service
Synchronizing state of postgresql.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable postgresql
Created symlink /etc/systemd/system/multi-user.target.wants/postgresql.service → /lib/systemd/system/postgresql.service.

Checking again:

sudo systemctl list-unit-files --type=service | grep postgres
UNIT FILE                                  STATE           VENDOR PRESET
postgresql.service                         enabled         enabled
postgresql@.service                        indirect        enabled
Ahmar
  • 584
  • 2
  • 7