OpenBSD 7.2上的PostgreSQL 14.5:安装
#postgres #database #backend #openbsd

概括

OpenBSD 7.2版本中,PostgreSQL被升级为14.5
这篇文章显示了如何将其安装在最新的OpenBSD上。

环境

  • OS:OpenBSD 7.2
  • DB:PostgreSQL 14.5

教程

概述

每个步骤稍后描述。

$ doas pkg_add postgresql-server

$ doas su - _postgresql
$ mkdir /var/postgresql/data

$ # --locale below is optional
$ initdb -D /var/postgresql/data -U postgres -A scram-sha-256 -E UTF-8 -W --locale=xx_XX.UTF-8
$ # will be asked password of the superuser, "postgres" above

$ exit

$ doas rcctl enable postgresql
$ doas rcctl start postgresql

单一步骤如下。

1.安装PostgreSQL Server

ports系统获取包裹:

$ doas pkg_add postgresql-server

输出为:

quirks-6.42 signed on 2022-10-30T18:56:25Z
postgresql-server-14.5:postgresql-client-14.5: ok
useradd: Warning: home directory `/var/postgresql' doesn't exist, and -m was not specified
postgresql-server-14.5: ok
The following new rcscripts were installed: /etc/rc.d/postgresql
See rcctl(8) for details.
New and changed readme(s):
    /usr/local/share/doc/pkg-readmes/postgresql-server

2.初始数据库

为了避免权限错误,将用户切换到上面创建的_postgresql

$ doas su - _postgresql

koude1创建目录:

$ mkdir /var/postgresql/data

运行initdb创建数据库群集:

$ initdb -D /var/postgresql/data -U postgres -A scram-sha-256 -E UTF-8 -W --locale=xx_XX.UTF-8

好吧,上面的-U postgres(= --user=...)是超级用户的名称。设置-W(= --pwprompt)时,将询问密码。 -W-A scram-sha-256(= --auth=...)是为了安全起见。 --locale=...是一个可选的,但是en_us.utf-8。

另外,文档(/usr/local/share/doc/pkg-readmes/postgresql-server)说:

强烈建议您不要使用Postgres DBA帐户
除了创建更多用户和/或数据库或用于管理任务外。
使用PostgreSQL权限系统确保数据库仅是
有权这样做的程序/用户访问。

结果,整个输出为:

The files belonging to this database system will be owned by user "_postgresql".
This user must also own the server process.

The database cluster will be initialized with locale "ja_JP.UTF-8".
initdb: could not find suitable text search configuration for locale "ja_JP.UTF-8"
The default text search configuration will be set to "simple".

Data page checksums are disabled.

Enter new superuser password: 
Enter it again: 

fixing permissions on existing directory /var/postgresql/data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 20
selecting default shared_buffers ... 128MB
selecting default time zone ... Asia/Tokyo
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

Success. You can now start the database server using:

    pg_ctl -D /var/postgresql/data -l logfile start

是的,成功。让我们从_postgersql用户exit

$ exit

3.启动PostgreSQL Server

激活守护程序并开始:

$ doas rcctl enable postgresql
$ doas rcctl start postgresql
postgresql(ok)

4.使用服务器

现在激活并启动了PostgreSQL Server守护程序。它用作RDBMS并听取客户的请求。

自动生成诸如Postgresql.conf和pg_hba.conf之类的配置文件,并安装了koude14

配置文件

它们对configure the server很有用。

PSQL

它被用作基于终端的前端。通过使用上面询问的密码,它可以连接到服务器:

$ psql -U postgres
Password for user postgres:

您将受到欢迎:)

psql (14.5)
Type "help" for help.

postgres=#

参考