9951 explained code solutions for 126 technologies


postgresqlHow can I set up and configure a PostgreSQL server?


  1. Install PostgreSQL using a package manager:
sudo apt-get install postgresql
  1. Create a database user:
sudo -u postgres createuser -s <username>
  1. Create a new database:
sudo -u postgres createdb <dbname>
  1. Configure authentication for the user:
sudo -u postgres psql
\password <username>
  1. Allow remote connections (optional): Edit the file /etc/postgresql/<version>/main/pg_hba.conf and add the line:
host <dbname> <username> <IP address> md5
  1. Edit the PostgreSQL configuration file postgresql.conf to allow remote connections: Change the line listen_addresses = 'localhost' to listen_addresses = '*'

  2. Restart the PostgreSQL service:

sudo service postgresql restart

Helpful links

Edit this code on GitHub