Skip to content

Instantly share code, notes, and snippets.

@ranraj
Last active May 26, 2020 05:08
Show Gist options
  • Save ranraj/bf6385e09a962346ee4e1b0677133f69 to your computer and use it in GitHub Desktop.
Save ranraj/bf6385e09a962346ee4e1b0677133f69 to your computer and use it in GitHub Desktop.
pg_sql
------------------------------------
Start on mac
------------------------------------
brew services start postgresql
------------
psql -d postgres
CREATE ROLE postgres PASSWORD 'password' SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN;
CREATE ROLE root PASSWORD 'admin' SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN;
pg_restore -U root -d database_name next.sql
psql -l
psql -U postgres -W
------------------------------------
command line useage
------------------------------------
psql -d postgres -U root -W
create database MyDB;
Ctrl+D
psql -d integration -U root -w
__________Remove_lock_in_postgres__________
SELECT * FROM pg_stat_activity order by query;
SELECT pg_cancel_backend('28908'); -- 28908
SELECT pg_cancel_backend('28966'); -- 28966
SELECT pg_cancel_backend('25945'); -- 28966
select count(*) from core_login;
____ DB Back up _postgress ____
pg_dump -U postgres -d student_db -h 192.1.2.1 -p 5432 > db_backup.sql
____ DB Restore _postgress ____
psql -U root -d student_db -h localhost < db_backup.sql
SELECT usename,client_hostname, client_addr, pid, now() - pg_stat_activity.query_start AS duration, query, state FROM pg_stat_activity WHERE (now() - pg_stat_activity.query_start) > interval '10 minutes';
Ohmysh
------
vi ~/.zshrc
export PATH=$HOME/bin:/usr/local/bin:$PATH
export PATH=/usr/local/Cellar/postgresql@9.4/9.4.25/bin:$PATH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment