Skip to content

Instantly share code, notes, and snippets.

@SanariSan
Last active February 27, 2022 17:21
Show Gist options
  • Save SanariSan/f3ea983c59c4be4ed7383dc94d86db67 to your computer and use it in GitHub Desktop.
Save SanariSan/f3ea983c59c4be4ed7383dc94d86db67 to your computer and use it in GitHub Desktop.
Postgre
# Setup
sudo apt install postgresql
# sudo pgcheck
sudo systemctl is-active postgresql
sudo systemctl is-enabled postgresql
sudo pg_isready
sudo systemctl status postgresql
# pgadmin4 install
curl https://www.pgadmin.org/static/packages_pgadmin_org.pub | sudo apt-key add
sudo sh -c 'echo "deb https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/$(lsb_release -cs) pgadmin4 main" > /etc/apt/sources.list.d/pgadmin4.list && apt update'
sudo apt install pgadmin4
sudo /usr/pgadmin4/bin/setup-web.sh
# Entering pg shell (pgsh)
sudo su - postgres
$ psql
(thiisdbname->)postgres=#
\connect dbname ?username
# Create db
CREATE USER uname WITH PASSWORD 'strongpwd';
CREATE DATABASE dbname;
GRANT ALL PRIVILEGES ON DATABASE dbname to uname;
GRANT USAGE, SELECT ON SEQUENCE name_id_seq TO user;
GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public TO user;
ALTER TABLE name
ADD COLUMN name VARCHAR;
# Reset counter
ALTER SEQUENCE tablename_id_seq RESTART WITH 1;
# Table
CREATE TABLE customers (
id SERIAL PRIMARY KEY,
customer_name VARCHAR NOT NULL
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment