Postgres, is a relational database management system that provides an implementation of the SQL querying language. It’s standards-compliant and has many advanced features like reliable transactions and concurrency without read locks.
PostgreSQL is used as the primary data store or data warehouse for many web, mobile, geospatial, and analytics applications.
Getting Started with Postgres
The quickest way of installing Postgres is to run the following commands.
install the Postgres package along with a
-contrib package that adds some additional utilities and functionality:
sudo apt install postgresql postgresql-contrib
By default, Postgres uses a concept called “roles” to handle authentication and authorization. These are, in some ways, similar to regular Unix-style users and groups.
When installed, Postgres is set to use authentication, which means it associates Postgres roles with the same Unix / Linux system account. If a role exists within Postgres, a Unix / Linux username with the same name can login as such.
The installation procedure created a user account called postgres that is associated with the default Postgres role. There are a few ways to utilize this account to access Postgres. One way is to switch over to the postgres account on your server by running the following command:
sudo -i -u postgres
Then you can access the Postgres prompt by running:
This will log you to PostgreSQL prompt, and from here you are free to interact with the database management system immediately.
To exit out of the PostgreSQL prompt, enter the following command:
This will bring you back to the postgres Linux command prompt. To return to your regular system user, run the
If, instead, you prefer to use
sudo for each command without switching from your normal account, run the following command:
sudo -u postgres createuser --interactive
Either way, the script will notify you of certain resolutions and, depending on your responses, issue specific Postgres commands to create a user to your specification.
super user access y/n
If issue occurs
When bundle on rails an error occurred while installing pg (1.2.3), and Bundler cannot continue.
Make sure that `gem install pg -v ‘1.2.3’ –source ‘ https://rubygems.org/SQL‘` succeeds before bundling.
Select only the generic stable version of PostgreSQL and install it. Be sure to choose the latest
sudo apt install postgresql-contrib libpq-dev
sudo apt install mlocate
sudo cp pg_hba.conf.sample pg_hba.conf
psql -U default_username (postgres in my case)
After that Restart Postgress Service.
sudo service postgresql restart
sudo service postgresql stop; sudo service postgresql start