PostgreSQL:修订间差异
跳到导航
跳到搜索
此页面具有访问限制。如果您看见此消息,则说明您没有权限访问此页面。
(→外部連結) |
无编辑摘要 |
||
第8行: | 第8行: | ||
== 設定 == | == 設定 == | ||
PostgreSQL 14的設定檔在<code>/etc/postgresql/14/main</code>下,通常會修改<code>postgresql.conf</code>將本來只聽localhost的改成聽所有界面: | PostgreSQL 14的設定檔在<code>/etc/postgresql/14/main</code>下,通常會修改<code>postgresql.conf</code>將本來只聽localhost的改成聽所有界面: | ||
第28行: | 第22行: | ||
== 常用指令 == | == 常用指令 == | ||
剛裝好的系統可以透過<code>postgres</code>這個帳號權限連進去: | |||
<syntaxhighlight lang="bash"> | |||
sudo -u postgres psql | |||
</syntaxhighlight> | |||
建立帳號與資料庫,這邊建立資料庫的部份用兩段式建立是為了閃開操作時的權限問題<ref>{{Cite web |url=https://stackoverflow.com/questions/26684643/error-must-be-member-of-role-when-creating-schema-in-postgresql |title="ERROR: must be member of role" When creating schema in PostgreSQL |language=en |accessdate=2021-11-12}}</ref>: | 建立帳號與資料庫,這邊建立資料庫的部份用兩段式建立是為了閃開操作時的權限問題<ref>{{Cite web |url=https://stackoverflow.com/questions/26684643/error-must-be-member-of-role-when-creating-schema-in-postgresql |title="ERROR: must be member of role" When creating schema in PostgreSQL |language=en |accessdate=2021-11-12}}</ref>: |
2023年4月25日 (二) 07:33的版本
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; sudo apt clean
设定
PostgreSQL 14的设定档在/etc/postgresql/14/main
下,通常会修改postgresql.conf
将本来只听localhost的改成听所有界面:
listen_addresses = '*'
另外修改pg_hba.conf
让外面可以连入,这边开放10.0.0.0/8
可以连:
echo "host all all 10.0.0.0/8 scram-sha-256" | sudo tee -a /etc/postgresql/14/main/pg_hba.conf; sudo service postgresql restart
常用指令
刚装好的系统可以透过postgres
这个账号权限连进去:
sudo -u postgres psql
建立账号与数据库,这边建立数据库的部分用两段式建立是为了闪开操作时的权限问题[1]:
CREATE USER exampleuser WITH ENCRYPTED PASSWORD 'password';
CREATE DATABASE exampledb;
ALTER DATABASE exampledb OWNER TO exampleuser;
授权给其他使用者操作:
GRANT ALL PRIVILEGES ON DATABASE exampledb TO exampleuser;
超级使用者:
ALTER USER exampleuser WITH SUPERUSER;
管理
列出所有database_name
下的schema,类似MySQL里的SHOW CREATE TABLE
:
pg_dump -d database_name -s -h hostname -U username
参考资料
- ↑ "ERROR: must be member of role" When creating schema in PostgreSQL. [2021-11-12] (English).
外部链接
- 官方网站 (英文)