Install PostgreSQL on Ubuntu 20.04

PostgreSQL Ubuntu

Install PostgreSQL on Ubuntu 20.04 by following these steps.

Update Package Lists: Open a terminal window and run the following command to update the package lists:

sudo apt update

Install PostgreSQL:

You can install PostgreSQL by running the following command:

sudo apt install postgresql

This will install PostgreSQL along with some necessary dependencies.

Verify Installation:

After the installation is complete, PostgreSQL should be up and running as a service. You can check the status of the PostgreSQL service with the following command:

sudo systemctl status postgresql

If it's running, you should see an output indicating that the service is active and running.

Access PostgreSQL:

By default, PostgreSQL creates a system user called postgres. You can switch to this user and access the PostgreSQL prompt with the following commands:

sudo -i -u postgres
psql

This will open the PostgreSQL prompt where you can start running SQL commands.

Set a Password for the postgres User (Optional):

If you want to set a password for the postgres user, you can do so with the following command:

sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'new_password';"

Replace 'new_password' with your desired password.

Create a New PostgreSQL User and Database (Optional):

You can create a new user and a new database with the following commands:

sudo -u postgres createuser --interactive
sudo -u postgres createdb mydatabase

Follow the prompts to create a new user and database.

Start and Enable PostgreSQL Service (Optional):

If PostgreSQL is not started automatically, you can start and enable the service with the following commands:

sudo systemctl start postgresql
sudo systemctl enable postgresql

This will ensure that PostgreSQL starts automatically when the system boots up.

Comments
Loading...
Sorry! No comment found:(

There is no comment to show for this.

Leave your comment