{"id":1853,"date":"2019-06-19T17:45:50","date_gmt":"2019-06-19T12:15:50","guid":{"rendered":"http:\/\/blog.tenthplanet.in\/?p=1853"},"modified":"2026-07-03T15:20:10","modified_gmt":"2026-07-03T09:50:10","slug":"postgresql-installation-in-rhel-7-with-different-data-directory","status":"publish","type":"post","link":"https:\/\/tenthplanet.in\/blogs\/postgresql-installation-in-rhel-7-with-different-data-directory\/","title":{"rendered":"Steps for Installation of Postgresql in RHEL 7 with different data directory"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Installation of Postgresql steps<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">By default, on CentOS 7, the PostgreSQL v10 data directory is located in \/var\/lib\/pgsql\/10\/data.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here\u2019s a simple trick to easily place it somewhere else without using symbolic links.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">First of all, install PostgreSQL 10:<\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\"># yum install -y download.postgresql.org\/pub\/repos\/yum\/10\/redhat\/rhel-7-x86_64\/pgdg-centos10-10-2.noarch.rpm<br># yum install -y postgresql10-server<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If you wish to place your data in (e.g.) \/database\/pg_data, create the directory with the good rights:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># mkdir -p \/database\/pg_data\n# chown -R postgres:postgres \/pgdata<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then, customize the systemd service:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># systemctl edit postgresql-10.service<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Add the following content:<\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">[Service]\nEnvironment=PGDATA=\/database\/pg_data<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This will create a \/etc\/systemd\/system\/postgresql-10.service.d\/override.conf file which will be merged with the original service file.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">To check its content:<\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\"># cat \/etc\/systemd\/system\/postgresql-10.service.d\/override.conf\n[Service]\nEnvironment=PGDATA=\/pgdata\/10\/data<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Reload systemd:<\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\"># systemctl daemon-reload<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Initialize the PostgreSQL data directory:<\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\"># \/usr\/pgsql-10\/bin\/postgresql-10-setup initdb<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Start and enable the service:<\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\"># systemctl enable postgresql-10\n# systemctl start postgresql-10<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Steps for Installation of Postgresql in RHEL 7 with different data directory<\/p>\n","protected":false},"author":23,"featured_media":1875,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[424],"tags":[535,27],"class_list":["post-1853","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-pentaho","tag-installation","tag-postgresql"],"acf":[],"_links":{"self":[{"href":"https:\/\/tenthplanet.in\/blogs\/wp-json\/wp\/v2\/posts\/1853","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tenthplanet.in\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tenthplanet.in\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tenthplanet.in\/blogs\/wp-json\/wp\/v2\/users\/23"}],"replies":[{"embeddable":true,"href":"https:\/\/tenthplanet.in\/blogs\/wp-json\/wp\/v2\/comments?post=1853"}],"version-history":[{"count":2,"href":"https:\/\/tenthplanet.in\/blogs\/wp-json\/wp\/v2\/posts\/1853\/revisions"}],"predecessor-version":[{"id":11463,"href":"https:\/\/tenthplanet.in\/blogs\/wp-json\/wp\/v2\/posts\/1853\/revisions\/11463"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/tenthplanet.in\/blogs\/wp-json\/wp\/v2\/media\/1875"}],"wp:attachment":[{"href":"https:\/\/tenthplanet.in\/blogs\/wp-json\/wp\/v2\/media?parent=1853"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tenthplanet.in\/blogs\/wp-json\/wp\/v2\/categories?post=1853"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tenthplanet.in\/blogs\/wp-json\/wp\/v2\/tags?post=1853"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}