이콜레모 개발자 위키

Page history of PostgreSQL



Title: PostgreSQL | edited by Youngrok Pak at 10 years, 1 month ago.

자주 까먹는 명령어

사용자 생성

create role <username> with login password <password>;

권한 지정

grant usage on schema public to <username>;
grant all on schema public to <username>;
grant all privileges on database <dbname> to <username>;
grant all on all tables in schema public to <username>
grant select on <table> to <username>;

읽기 전용 계정 만들기 http://stackoverflow.com/questions/760210/how-do-you-create-a-read-only-user-in-postgresql

GRANTCONNECTONDATABASE mydb TO xxx;
GRANT USAGE ONSCHEMApublicTO xxx;
GRANTSELECTON mytable TO xxx;
GRANTSELECTONALL TABLES INSCHEMApublicTO xxx;

커넥션 현황 보기

SELECT count(*) from pg_stat_activity;

파이썬에서 사용하기

import psycopg2
conn = psycopg2.connect('host=db.com user=youngrok password=blahblah dbname=mydb
cursor = conn.cursor()
cursor.execute('SELECT * FROM auth_user')
print cursor.fetchall()

 

Wiki at WikiNamu