27
loading...
This website collects cookies to deliver better user experience
# 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
sudo systemctl stop postgresql.service
sudo systemctl start postgresql.service
sudo systemctl enable postgresql.service
sudo passwd postgres
# ALTER USER command to change the password for the postgres user:
ALTER USER postgres PASSWORD 'myPassword';
ALTER ROLE;
sudo -u postgres psql
# or run this command
sudo su -l postgres
\q
# Get list of databases
\l
# Get list of databases with size & description
\l+
\dt
create database database_name;
\c database_name
\dt
\d table_name
SELECT pg_database_size('database_name');
sudo -u postgres createdb database_name
sudo -u postgres dropdb
sudo -u postgres psql database_name