Moving the location of the PostGIS database

One does not normally need to change the location of the PostgreSQL/PostGIS database on the file system, but it can be done.

By default, the database is typically located in the following locations:

Operating system File path
Windows C:\ProgramData\Boundless\OpenGeo\pgsql\9.3
OS X ~/Library/Application\ Support/PostGIS
Ubuntu Linux /var/lib/postgresql/9.3/main
Red Hat / CentOS Linux /var/lib/pgsql/9.3/data

Please see the instructions specific to your operating system.

Windows

  1. Open Windows Services (typically Control Panel ‣ Administrative Tools ‣ Services or Start ‣ Run ‣ services.msc) and stop the OpenGeo PostgreSQL service.

    Note

    You can also use the Stop shortcut for PostGIS in the Start Menu.

  2. Open the file pg_config.cmd, typically located in C:\Program Files (x86)\Boundless\OpenGeo\bin, in a text editor. (For permissions reasons, you may wish to open the text editor as an administrator.)

  3. Change the line:

    set pg_data_dir=%data%\pgsql\%pg_version%\
    

    to:

    set pg_data_dir=<NEWPATH>
    

    where <NEWPATH> would be the desired path (such as D:\pgdata)

  4. Start the OpenGeo PostgreSQL service.

OS X

  1. Quit the PostGIS application using the menu.

  2. In a terminal, move the location of the data directory:

    sudo mv ~/Library/Application\ Support/PostGIS <NEWPATH>
    

    where <NEWPATH> would be the desired path (such as ~/pgdata)

  3. Create a symlink from the old path the new one:

    ln -s ~/Library/Application\ Support/PostGIS <NEWPATH>
    
  4. Launch PostGIS.

Ubuntu Linux

There are two ways to accomplish this in Ubuntu: use a symlink or edit the configuration file.

Using a symlink:

  1. Stop the PostgreSQL service:

    sudo service postgresql stop
    
  2. Move the location of the data directory:

    sudo mv /var/lib/postgresql/9.3/main <NEWPATH>
    

    where <NEWPATH> would be the desired path (such as /opt/pgdata)

  3. Create a symlink from the old path the new one:

    ln -s /var/lib/postgresql/9.3/main <NEWPATH>
    
  4. Start the PostgreSQL service:

    sudo service postgresql start
    

Editing the configuration file:

  1. Stop the PostgreSQL service:

    sudo service postgresql stop
    
  2. Move the location of the data directory:

    sudo mv /var/lib/postgresql/9.3/main <NEWPATH>
    

    where <NEWPATH> would be the desired path (such as /opt/pgdata)

  3. Open /etc/postgresql/9.3/main/postgresql.conf in a text editor (with super user privileges).

  4. Find the line that reads data_directory=/var/lib/postgresql/9.3/main and change the path to the <NEWPATH> determined above.

  5. Save and close the file.

  6. Start the PostgreSQL service:

    sudo service postgresql start
    

Red Hat / CentOS Linux

There are two ways to accomplish this in Red Hat / CentOS: use a symlink or edit the configuration file.

Using a symlink:

  1. Stop the PostgreSQL service:

    sudo service postgresql-9.3 stop
    
  2. Move the location of the data directory:

    sudo mv /var/lib/pgsql/9.3/data <NEWPATH>
    

    where <NEWPATH> would be the desired path (such as /opt/pgdata)

  3. Create a symlink from the old path the new one:

    ln -s /var/lib/pgsql/9.3/data <NEWPATH>
    
  4. Start the PostgreSQL service:

    sudo service postgresql-9.3 start
    

Editing the configuration file:

  1. Stop the PostgreSQL service:

    sudo service postgresql-9.3 stop
    
  2. Move the location of the data directory:

    sudo mv /var/lib/pgsql/9.3/data <NEWPATH>
    

    where <NEWPATH> would be the desired path (such as /opt/pgdata)

  3. Open /etc/rc.d/init.d/postgresql-9.3 in a text editor (with super user privileges).

  4. Find the line that starts with PGDATA and and change the path to the <NEWPATH> determined above.

  5. Save and close the file.

  6. Start the PostgreSQL service:

    sudo service postgresql start