Skip to content

Instantly share code, notes, and snippets.

@kana-ph
Last active March 15, 2017 10:50
Show Gist options
  • Save kana-ph/cbbc951ffd977c4770b8da03441157c5 to your computer and use it in GitHub Desktop.
Save kana-ph/cbbc951ffd977c4770b8da03441157c5 to your computer and use it in GitHub Desktop.
PSQL Install/Setup Guide

Installing postgresql

Fedora, RHEL, CentOS, or similar OS

# yum install postgresql
# yum install postgresql-server

Debian, Ubuntu, Mint, or similar OS

# apt-get install postgresql

Initialize postgresql Files

# postgresql-setup initdb

Setup postgresql

  1. Set method of the address 127.0.0.1 and ::1 to trust at the pg_hba.conf file. The directory might not be visible to non-sudoers. Run sudo su first.

    • In Fedora, RHEL, CentOS, or similar OS, the file location is /var/lib/pgsql/data/pg_hba.conf
    • In Debian, Ubuntu, Mint, or similar OS, the file location is /etc/postgresql/$version/main/pg_hba.conf
  2. Login to psql shell:

    $ psql --host=localhost --user=postgres
    
  3. Set password inside psql shell:

    \password
    
  4. Logout of psql shell with \q or press Ctrl+D on your keyboard.

  5. Return method of the address 127.0.0.1 and ::1 to md5 at the pg_hba.conf file.

    • Just revert the action on Step #1
  6. Restart postgres service:

    # service postgresql restart
    
  7. Login to psql shell again with the password you set.

    $ psql --host=localhost --user=postgres
    

    This action should prompt you with password.

⚠️ Command service postgresql restart might not work. Enable first the postgres service:

# systemctl enable postgresql.service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment