xxxxxxxxxx
# Step 1 — Installing PostgreSQL
sudo apt update
sudo apt install postgresql postgresql-contrib
sudo systemctl start postgresql.service
# Step 2 — Creating a New Role
sudo -u postgres createuser --interactive --pwprompt
# Step 3 - Accessing
sudo -u postgres psql
# connection string
# https://linuxhint.com/understand-postgres-connection-string/
postgers://localhost
#If a username and a password are needed, the updated URI looks like this:
postgres://<username>:<password>@localhost
xxxxxxxxxx
# Step 1: Update package list
sudo apt update
# Step 2: Install PostgreSQL and related packages
sudo apt install postgresql postgresql-contrib
# Step 3: Check the PostgreSQL service status
sudo service postgresql status
# Step 4: Create a new PostgreSQL role with superuser privileges
sudo su - postgres
psql
CREATE ROLE myuser WITH LOGIN SUPERUSER PASSWORD 'mypassword';
\q
exit
# Step 5: Test the PostgreSQL installation
psql -U myuser -h localhost
# Congratulations! PostgreSQL is now installed and ready to use on your Ubuntu system.
xxxxxxxxxx
# Step 1: Update package lists
sudo apt update
# Step 2: Install PostgreSQL
sudo apt install postgresql
# Step 3: Verify the installation by checking the PostgreSQL version
psql --version
# Step 4: Connect to the PostgreSQL database
sudo su - postgres # Switch to the postgres user
psql # Connect to the database
# Step 5: Create and manage databases or execute SQL commands
-- Create a new database
CREATE DATABASE my_database;
-- Create a new user
CREATE USER my_user WITH ENCRYPTED PASSWORD 'password';
-- Grant privileges to the user on the database
GRANT ALL PRIVILEGES ON DATABASE my_database TO my_user;
-- Exit the PostgreSQL prompt
\q
# Step 6: Connect to the database with a specific user
psql -U my_user -d my_database
xxxxxxxxxx
# from the official postgresql site: https://www.postgresql.org/download/linux/ubuntu/
# this will install the latest version of the postgresql.
# Create the file repository configuration:
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
# Import the repository signing key:
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
# Update the package lists:
sudo apt-get update
# Install the latest version of PostgreSQL.
# If you want a specific version, use 'postgresql-12' or similar instead of 'postgresql':
sudo apt-get -y install postgresql
xxxxxxxxxx
# 1. Add official repository to list of registered repos
sudo apt install -y postgresql-common
sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh
# 2. Update and install latest one
sudo apt update
sudo apt install postgresql-15
xxxxxxxxxx
$ sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
Code language: Shell Session (shell)