skip to Main Content

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.

7

Answers


  1. 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.

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
  3. 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
    [email protected]                        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
    [email protected]                        indirect        enabled
    
    Login or Signup to reply.
  4. 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

    Login or Signup to reply.
  5. 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.

    Login or Signup to reply.
  6. 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
    
    Login or Signup to reply.
  7. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search