9951 explained code solutions for 126 technologies


postgresqlHow do I install and configure PostgreSQL on Ubuntu?


  1. Install PostgreSQL on Ubuntu:
    sudo apt-get install postgresql postgresql-contrib
  2. Create a New Database and User:
    sudo -u postgres psql
    CREATE DATABASE mydb;
    CREATE USER myuser WITH PASSWORD 'mypass';
    GRANT ALL PRIVILEGES ON DATABASE mydb TO myuser;
  3. Configure PostgreSQL:
    • Edit the pg_hba.conf file to control the authentication method.
    • Edit the postgresql.conf file to configure the parameters of the server.
  4. Restart the PostgreSQL Service:
    sudo /etc/init.d/postgresql restart
  5. Connect to the Database:
    psql -h localhost -U myuser mydb

Helpful links

Edit this code on GitHub