PostgreSQL的备忘录[附加方式]

完全是个人使用的PostgreSQL备忘录。

※ 只是作为个人备忘的完全记录,将随时添加补充内容。

当更新了PostgreSQL时

To migrate existing data from a previous major version of PostgreSQL run:
  brew postgresql-upgrade-database

This formula has created a default database cluster with:
  initdb --locale=C -E UTF-8 /usr/local/var/postgres
For more details, read:
  https://www.postgresql.org/docs/14/app-initdb.html

To start postgresql:
  brew services start postgresql
Or, if you don't want/need a background service you can just run:
  /usr/local/opt/postgresql/bin/postgres -D /usr/local/var/postgres
$ cat /usr/local/var/log/postgresql.log

FATAL:  database files are incompatible with server
DETAIL:  The data directory was initialized by PostgreSQL version 13, which is not compatible with this version 14.0.

更改数据库的所有者

ALTER DATABESE [DB_NAME] OWNER [OWNER_NAME] TO [NEW_OWNER_NAME];

角色系

角色列表

\du

创建角色

CREATE ROLE [ROLE_NAME];

授予权限以创建角色

请以默认用户所拥有的权限为例进行改述。

CREATE ROLE [ROLE_NAME] WITH SUPERUSER CREATEROLE CREATEDB REPLICATION BYPASSRLS;

给予Role权限

以默认用户权限为例

ALTER ROLE [ROLE_NAME] SUPERUSER CREATEROLE CREATEDB REPLICATION BYPASSRLS;

删除角色

DROP ROLE [ROLE_NAME];
bannerAds