从安装到启动/停止PostgreSQL

为了不忘记关于PostgreSQL的事情,要迅速回忆一下。

本次的环境

    • macOS Mojave 10.14.5

 

    postgresql-11.4

使用Homebrew安装PostgreSQL。

$ brew install postgresql
~~
==> Summary
?  /usr/local/Cellar/postgresql/11.4: 3,188 files, 35.4MB
~~

完成只需要几分钟。

确认已经完全进入了。

$ postgres --version     /* psql -V でもOK */
postgres (PostgreSQL) 11.4

用UTF-8初始化数据库。

$ initdb /usr/local/var/postgres -E utf8
The files belonging to this database system will be owned by user "sf213471118".
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.

initdb: directory "/usr/local/var/postgres" exists but is not empty
If you want to create a new database system, either remove or empty
the directory "/usr/local/var/postgres" or run initdb
with an argument other than "/usr/local/var/postgres".

准备好了。

请启动/关闭PostgreSQL

如果使用Mac,使用Homebrew的”brew services”命令会很方便。

只需要将下面的postgreSQL部分更改一下即可,如果使用MySQL。

启动postgreSQL

$ brew services start postgresql
==> Successfully started `postgresql` (label: homebrew.mxcl.postgresql)

启动完成。

停止postgreSQL

$ brew services stop postgresql
Stopping `postgresql`... (might take a while)
==> Successfully stopped `postgresql` (label: homebrew.mxcl.postgresql)     

已经停止了。

查看PostgreSQL的启动状态。

这是启动状态

$ brew services list
Name       Status  User     Plist
postgresql started sf213471118 /Users/sf213471118/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

这是停止状态 (Zhè shì

$ brew services list
Name       Status  User     Plist
postgresql stopped
广告
将在 10 秒后关闭
bannerAds