Giter VIP home page Giter VIP logo

postgresql-server's Introduction

Contents

- Install PostgresSQL server on Ubuntu and remote access with Python

Build PostgresSQL Server

Step 1. Install PostgresSQL Server

- Check which version of PostgreSQL to install on Ubuntu

apt show postgresql

- PostgreSQL Package Setting

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

- Install PostgreSQL on Ubuntu

sudo apt-get -y install postgresql
sudo apt install postgresql postgresql-contrib

- Run PostgresSQL service

sudo service postgresql start

- Show PostgreSQL status

sudo service postgresql status

Step 2. Set PostgresSQL Admin Account

- Connect PostgresSQL Server and

sudo -i -u postgres
psql

- Confirm the current connection and user information

\conninfo

- Set Passwords of PostgresSQL Admin Account

  • 'postgres' is default admin account of PostgresSQL
ALTER USER postgres WITH PASSWORD '{passwords}';

- Show PostgresSQL Accounts

\du

Step 3. Create PostgresSQL Database

- Create PostgresSQL Database

  • Set Owner as 'postgres'
CREATE DATABASE {db_name} OWNER postgres;

- Show PostgresSQL Database

\list

- Disconnect PostgresSQL Server

exit

Step 4. Allow Remote Access

- Move to path of PostgresSQL configs file

cd /etc/postgresql/{version_of_PostgresSQL}/main

- Edit 'postgresql.conf' file

  • 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

- Restart PostgresSQL service

  • For applying modified configs file
sudo service postgresql restart

- Edit 'pg_hba.conf' file

  • Add line as follow for allowing to connect all IPs

sudo nano pg_hba.conf

- Restart PostgresSQL service

  • For applying modified configs file
sudo service postgresql restart

Step 5. Test Remote Access

- Test remote access to PostgresSQL server and running query

  • 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}'

- Confirm data in created database

sudo -i -u postgres
psql -d {db_name} -U postgres -W
SELECT * FROM {table_name};

postgresql-server's People

Contributors

qbxlvnf11 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.