• Home
  • Docker
  • Kubernetes
  • LLMs
  • Java
  • Ubuntu
  • Maven
  • Big Data
  • Archived
Install | PostgreSQL
  1. References
  2. Installation (Red Hat)
  3. Move PostgreSQL Data Directory to a New Location
  4. Enable automatic start
  5. Change postgres password
  6. Configure PostgreSQL to allow remote connection
  7. Use psql command
  8. Create new user (role)
  9. Create new database
  10. Backup and Restore
  11. Error Reporting and Logging
  12. Install PostgreSQL 9.6 (Ubuntu)
  13. Fix the error "PostgreSQL version x is not installed" (Ubuntu)

  1. References
    See this page for more details on how to install PostgreSQL:
    https://www.postgresql.org/download/linux/redhat/
  2. Installation (Red Hat)

    Initialize PostgreSQL database:
    Change postgres password:
  3. Move PostgreSQL Data Directory to a New Location
  4. Enable automatic start

    Check PostgreSQL version:
  5. Change postgres password
    Switch to postgres user:
    Change postgres database user password:
  6. Configure PostgreSQL to allow remote connection
    Switch to postgres user:
    Configure g_hba.conf:
    Note: md5 means that you need to provide a password to connect to PostgreSQL. Use trust to connect without providing a password.

    Configure postgresql.conf:
    Restart PostgreSQL:
    Test PostgreSQL connection:
  7. Use psql command
    You need to switch to postgres user otherwise you might get an error if your run psql command:
    Switch to postgres user:
    Run psql command:
    To exit from PostgreSQL command line utility psql:
    Use psql to connect to a remote host:
    Use psql to connect to a remote host (provide password in the command line):
    Use psql to connect to a remote host (provide password using the ~/.pgpass file):

    Use psql to run a query on a remote host:
  8. Create new user (role)
    Run psql command and execute the command CREATE ROLE to create a new role:
    Execute the command ALTER ROLE to assign permission to a user:
    Execute the command drop user to delete a user:
  9. Create new database
    Run psql command and execute the command CREATE DATABASE to create a new database:
    Run psql command and execute the command GRANT ALL to grant privileges on a database:
    Execute the command drop database to delete a database:
  10. Backup and Restore
    Use pg_dump tool to backup a database:
    Use psql to restore a database:
  11. Error Reporting and Logging
    See this page for more details about Error Reporting and Logging:
    https://www.postgresql.org/docs/current/static/runtime-config-logging.html

    Configure postgresql.conf:
  12. Install PostgreSQL 9.6 (Ubuntu)



    You have to configure the files "pg_hba.conf" and "postgresql.conf" as seen above.
    These files can found by default in this location: /etc/postgresql/9.6/main
  13. Fix the error "PostgreSQL version x is not installed" (Ubuntu)
    When installing/uninstalling different versions of PostgreSQL, you might get this error when you try to run PostgreSQL tools:

    If you already uninstalled PostgreSQL 11, you can try to purge the installation and that in some cases should be enough to fix the issue:

    But let say the above didn't fix the issue or the system start complaining about a new version of PostgreSQL:

    Let's check PostgreSQL cluster:

    Check if you still have these folders:


    Let's delete any left folders from PostgreSQL 10 installation:

    Check now pg_lsclusters:

    Run psql:
© 2025  mtitek