Search code examples
linuxpostgresqlbashcentosenvironment

pg_ctl is not found after install postgresql12-server from pgdg repository in CentOS 8


I've recently installed PostgreSQL 12 through PostgreSQL official repositories (not CentOS). (https://yum.postgresql.org/12/redhat/rhel-8-x86_64)

However, pg_ctl command is not found after the setup process.

I've I do:

rpm -ql postgresql12-server |grep pg_ctl
/usr/pgsql-12/bin/pg_ctl
/usr/pgsql-12/share/man/man1/pg_ctl.1

It is not loaded pgsql-12 directory in PATH environment variable. I've got a looking inside /etc/profile.d/ I got this:

ls /etc/profile.d/
colorgrep.csh  colorxzgrep.csh  colorzgrep.csh  csh.local  gawk.sh   lang.sh   less.sh
colorgrep.sh   colorxzgrep.sh   colorzgrep.sh   gawk.csh   lang.csh  less.csh  sh.local

So... I didn't found any files named or referenced to pgsql.

I perform:

grep -rlio pgsql /etc/profile.d/

I didn't get anything... so, I understand why is not located pg_ctl by Bash.

postgres user cannot find it too. (I thought that's got a .bash_profile with PATH inside but It's not)


Solution

  • How to solve this?

    • Create a file in /etc/profile.d/pgsql.sh

    • Add the follows lines and save the file:

    #!/bin/bash
    PATH=${PATH}:/usr/pgsql-12/bin
    export PATH
    
    • Run this to update current PATH:
    source /etc/profile.d/pgsql.sh
    
    • Check the PATH now:
    echo $PATH
    /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/pgsql-12/bin
    
    • Run pg_ctl --help:
    pg_ctl is a utility to initialize, start, stop, or control a PostgreSQL server.
    
    Usage:
    [...]
    

    That's all!