PostgreSQL:修订间差异
跳到导航
跳到搜索
此页面具有访问限制。如果您看见此消息,则说明您没有权限访问此页面。
无编辑摘要 |
(→設定) |
||
第9行: | 第9行: | ||
== 設定 == | == 設定 == | ||
=== postgresql.conf === | |||
<syntaxhighlight lang=" | PostgreSQL 14的設定檔在<code>/etc/postgresql/14/main</code>下,其他版本的依此類推,通常會修改<code>postgresql.conf</code>將本來只聽localhost的改成聽所有界面: | ||
<syntaxhighlight lang="ini"> | |||
listen_addresses = '*' | listen_addresses = '*' | ||
</syntaxhighlight> | </syntaxhighlight> | ||
另外可以修改<code>work_mem</code>,預設是4MB,調大一點會對於排序相關的操作有幫助<ref>{{Cite web |url=https://aws.amazon.com/blogs/database/tune-sorting-operations-in-postgresql-with-work_mem/ |title=Tune sorting operations in PostgreSQL with work_mem |language=en |accessdate=2023-04-25 |date=2021-10-16}}</ref>: | |||
<syntaxhighlight lang="ini"> | |||
work_mem = 16MB | |||
</syntaxhighlight> | |||
=== pg_hba.conf === | |||
另外修改<code>pg_hba.conf</code>讓外面可以連入,這邊開放<codE>10.0.0.0/8</code>可以連: | 另外修改<code>pg_hba.conf</code>讓外面可以連入,這邊開放<codE>10.0.0.0/8</code>可以連: |
2023年4月25日 (二) 07:36的版本
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.conf
PostgreSQL 14的设定档在/etc/postgresql/14/main
下,其他版本的依此类推,通常会修改postgresql.conf
将本来只听localhost的改成听所有界面:
listen_addresses = '*'
另外可以修改work_mem
,预设是4MB,调大一点会对于排序相关的操作有帮助[1]:
work_mem = 16MB
pg_hba.conf
另外修改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
建立账号与数据库,这边建立数据库的部分用两段式建立是为了闪开操作时的权限问题[2]:
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
参考资料
- ↑ Tune sorting operations in PostgreSQL with work_mem. 2021-10-16 [2023-04-25] (English).
- ↑ "ERROR: must be member of role" When creating schema in PostgreSQL. [2021-11-12] (English).
外部链接
- 官方网站 (英文)