Project

General

Profile

Support #553

Updated by Daniel Curtis over 9 years ago

This is a simple guide for setting up a standalone PostgreSQL database server on Debian. 

 * Use sudo to get a root shell 
 <pre> 
 sudo -s 
 </pre> 

 * Update the system: 
 <pre> 
 apt-get update && sudo apt-get upgrade 
 </pre> 

 h1. Install PostgreSQL 

 * Install PostgreSQL 
 <pre> 
 apt-get install postgresql postgresql-client 
 </pre> 

 h2. Create a database and user 

 * Create a regular system user account using adduser (skip this step to use an existing account): 
 <pre> 
 adduser somepguser 
 </pre> 

 * Connect to the default database: 
 <pre> 
 su - postgres 
 psql 
 </pre> 
 #* Set a password for the postgres user: 
 <pre> 
 \password postgres 
 </pre> 
 #* The postgres admin console will show @postgres=#@, create a new user: database user and a database: 
 <pre> 
 CREATE USER somepguser WITH PASSWORD 'somepguserpass'; 
 </pre> 
 #* And a create a database: 
 <pre> 
 CREATE DATABASE somepgdatabase OWNER somepguser; 
 </pre> 
 #* Quit from the database 
 <pre> 
 \q 
 </pre> 

 * Exit from the postgres user 
 <pre> 
 exit 
 </pre> 

 * Connect as somepguser to the new database: 
 <pre> 
 su - somepguser 
 psql somepgdatabase 
 </pre> 

 h3. Enable Network Service 

 * Edit the main postgresql config: 
 <pre> 
 nano /etc/postgresql/9.4/main/postgresql.conf 
 </pre> 
 #* And change the @listen_addresses@ parameter: 
 <pre> 
 listen_addresses = '*' 
 </pre> 

 * Then append a rule to allow access from a given subnet: 
 <pre> 
 echo "host      all       all       192.168.0.0/24    trust" >> /etc/postgresql/9.4/main/pg_hba.conf 
 </pre> 

 * And restart postgresql: 
 <pre> 
 service postgresql restart 
 </pre> 

 h2. Resources 

 * https://wiki.debian.org/PostgreSql

Back