首页 > 解决方案 > Postgresql:如何将它安装在 linux 服务器的不同位置?

问题描述

我想安装postgresql在 linux (ubuntu) 服务器上。

如果我执行以下操作:

sudo apt-get install postgresql

它将安装它

/var/lib/postgresql/9.5/main

虽然我想把它放进去

/home/database/postgresql/9.5/main

标签: postgresqlubuntu

解决方案


Postgres 使用PGDATA环境变量来了解您希望它在哪里工作。编辑初始化脚本(/etc/init.d/postgresql/usr/lib/systemd/postgresql.service)并PGDATA相应地设置。例如:

# Note: changing PGDATA will typically require adjusting SELinux
# configuration as well.

# Note: do not use a PGDATA pathname containing spaces, or you will
# break postgresql-setup.
[Unit]
Description=PostgreSQL database server
After=syslog.target
After=network.target

[Service]
Type=forking

User=postgres
Group=postgres

# Note: avoid inserting whitespace in these Environment= lines, or you may
# break postgresql-setup.

# Location of database directory
Environment=PGDATA=/var/sql/pgsql/

# Where to send early-startup messages from the server (before the logging
# options of postgresql.conf take effect)
# This is normally controlled by the global default set by systemd
# StandardOutput=syslog

# Disable OOM kill on the postmaster
OOMScoreAdjust=-1000

#ExecStartPre=/usr/local/pgsql/bin/postgresql95-check-db-dir ${PGDATA}
ExecStart=/usr/local/pgsql/bin/pg_ctl start -D ${PGDATA} -s -w -t 300
ExecStop=/usr/local/pgsql/bin/pg_ctl stop -D ${PGDATA} -s -m fast
ExecReload=/usr/local/pgsql/bin/pg_ctl reload -D ${PGDATA} -s

# Give a reasonable amount of time for the server to start up/shut down
TimeoutSec=300

[Install]
WantedBy=multi-user.target  

您也可以尝试符号链接/var/lib/postgresql/9.5/main/home/database/postgresql/9.5/main- 可能更简单。


推荐阅读