{"id":4611,"date":"2015-04-26T19:18:44","date_gmt":"2015-04-26T11:18:44","guid":{"rendered":"http:\/\/rmohan.com\/?p=4611"},"modified":"2015-04-26T19:18:44","modified_gmt":"2015-04-26T11:18:44","slug":"changing-the-default-postgresql-data-folder-pgdata","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=4611","title":{"rendered":"Changing the default PostgreSQL data folder (PGDATA)"},"content":{"rendered":"<p>Installing the PostgreSQL server on RHEL, CentOS, Scientific Linux or Fedora installs the PostgreSQL databases and configuration files in \u201c\/var\/lib\/pgsql\/data\u201d.<\/p>\n<p>This may or may not be desirable. Let\u2019s assume for a moment you have a separately crafted partition for PostgreSQL to use, let\u2019s say a RAID10 volume. You\u2019d want to change this.<\/p>\n<h2>Change the defaults<\/h2>\n<p>Use your favorite text editor, in my case nano to create the following file (must be the same as the name of the service)<\/p>\n<pre># nano \/etc\/sysconfig\/pgsql\/postgresql<\/pre>\n<p>Add the following<\/p>\n<pre>PGDATA=\/postgresql\/data<\/pre>\n<p>Optionally you can also add the following to change the default port (example is the default port)<\/p>\n<pre>PGPORT=5432<\/pre>\n<h2>Adjusting SELinux to permit the new data folder (pgdata) location<\/h2>\n<p>Should the following command output \u201cPermissive\u201d or \u201cDisabled\u201d then you may skip the details for SELinux.<\/p>\n<pre># getenforce<\/pre>\n<p>Run the semanage command to add a context mapping for \/opt\/postgresql and any other directories\/files within it.<\/p>\n<pre># semanage fcontext -a -t postgresql_db_t \"\/postgresql\/data(\/.*)?\"<\/pre>\n<p>Now use the restorecon command to apply this context mapping to the running system<\/p>\n<pre># restorecon -Rv \/postgresql\/data<\/pre>\n<h2>Starting PostgreSQL<\/h2>\n<pre># chkconfig --levels 345 postgresql on<\/pre>\n<pre># service postgresql initdb<\/pre>\n<pre># service postgresql start<\/pre>\n<p>You\u2019re all set to go! Keep in mind that PostgreSQL listens to \u2018localhost\u2019 by default. To change this you need to alter the \u201clisten_address\u201d parameter in \u201c\/var\/lib\/pgsql\/data\/postgresql.conf\u201d (change will require restart).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Installing the PostgreSQL server on RHEL, CentOS, Scientific Linux or Fedora installs the PostgreSQL databases and configuration files in \u201c\/var\/lib\/pgsql\/data\u201d.<\/p>\n<p>This may or may not be desirable. Let\u2019s assume for a moment you have a separately crafted partition for PostgreSQL to use, let\u2019s say a RAID10 volume. You\u2019d want to change this.<\/p>\n<p> Change the defaults [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,4,29],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/4611"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4611"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/4611\/revisions"}],"predecessor-version":[{"id":4612,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/4611\/revisions\/4612"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4611"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4611"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4611"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}