apt show postgresql
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list. d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get -y install postgresql
sudo apt install postgresql postgresql-contrib
sudo service postgresql start
sudo service postgresql status
sudo -i -u postgres
psql
\conninfo
- 'postgres' is default admin account of PostgresSQL
ALTER USER postgres WITH PASSWORD '{passwords}';
\du
- Set Owner as 'postgres'
CREATE DATABASE {db_name} OWNER postgres;
\list
exit
cd /etc/postgresql/{version_of_PostgresSQL}/main
- Set 'listen_addresses' as '0.0.0.0' for listening to all IPs
- Set 'port' to the port you want to connect to
sudo nano postgresql.conf
- For applying modified configs file
sudo service postgresql restart
- Add line as follow for allowing to connect all IPs
sudo nano pg_hba.conf
- For applying modified configs file
sudo service postgresql restart
- Custom python PostgresSQL server class
- Connect PostgreSQL server, Create table, Insert data, Select data etc.
python db_test --host '{server_ip}' --port {port} --db_name '{db_name}' --user 'postgres' --password '{password}' --table_name '{table_name}'
sudo -i -u postgres
psql -d {db_name} -U postgres -W
SELECT * FROM {table_name};