PostgreSQL

来自Gea-Suan Lin's Wiki
跳到导航 跳到搜索

PostgreSQL是一套RDBMS

安裝

sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'; wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -; sudo apt update; sudo apt install -y postgresql

常用指令

建立資料庫與帳號:

CREATE DATABASE exampledb;
CREATE USER exampleuser WITH ENCRYPTED PASSWORD 'password';
GRANT ALL PRIVILEGES ON DATABASE exampledb TO exampleuser;

管理

列出所有database_name下的schema,類似MySQL裡的SHOW CREATE TABLE

pg_dump -d database_name -s -h hostname -U username

外部連結