美文网首页SonarQube
Postgres初始化数据库目录

Postgres初始化数据库目录

作者: 戈壁堂 | 来源:发表于2020-11-04 09:56 被阅读0次

    安装完成后,可以切换到root用户执行/usr/pgsql-10/bin/postgresql-10-setup initdb,但不建议直接这样做

    根据官方文档initdb说明:

    Although initdb will attempt to create the specified data directory, it might not have permission if the parent directory of the desired data directory is root-owned. To initialize in such a setup, create an empty data directory as root, then use chown to assign ownership of that directory to the database user account, then su to become the database user to run initdb.

    initdb must be run as the user that will own the server process, because the server needs to have access to the files and directories that initdb creates. Since the server cannot be run as root, you must not run initdb as root either. (It will in fact refuse to do so.)

    默认的数据库目录为/var/lib/pgsql/10/data/可以先使用root用户创建一个空的文件夹,再使用chown将此文件夹权限赋值给postgres用户,然后再执行initdb目录指定-D参数值为上述目录

    Custom PGDATA with systemd

    # mkdir -p /pgdata/10/data
    # chown -R postgres:postgres /pgdata
    

    Then, customize the systemd service: systemctl edit postgresql-10.service Add the following content:

    [Service]
    Environment=PGDATA=/pgdata/10/data
    

    This will create a
    /etc/systemd/system/postgresql-10.service.d/override.conf file which will be merged with the original service file.

    To check its content:

    # cat /etc/systemd/system/postgresql-10.service.d/override.conf
    [Service]
    Environment=PGDATA=/pgdata/10/data
    

    Reload systemd:

    # systemctl daemon-reload
    

    Initialize the PostgreSQL data directory:

    # /usr/pgsql-10/bin/postgresql-10-setup initdb
    

    Start and enable the service:

    # systemctl enable postgresql-10
    # systemctl start postgresql-10
    

    相关文章

      网友评论

        本文标题:Postgres初始化数据库目录

        本文链接:https://www.haomeiwen.com/subject/xsdivktx.html