# Postgres data directory in SLES11

**URL:** <https://forums.suse.com/t/postgres-data-directory-in-sles11/32942>\
**Category:** SLES Configure-Administer\
**Created:** [September 19, 2018, 9:57pm UTC](https://forums.suse.com/t/postgres-data-directory-in-sles11/32942 "2018-09-19T21:57:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mlino](https://avatars.discourse-cdn.com/v4/letter/m/a5b964/32.png) [@mlino](https://forums.suse.com/u/mlino)\
**Post date:** [September 19, 2018, 9:57pm UTC](https://forums.suse.com/t/postgres-data-directory-in-sles11/32942/1 "2018-09-19T21:57:47Z")

</div>

Hello,

I have installed Postgresql94 using zypper and I would like to change the data directory. I alraedy have a database, so I would like to migrate it to the new location and then change the location in the postgresql configuration.

I Have tried to make the change, but I was unable to manage to restart postgres server again.

Regards,

Marcio

---

<div class="post-metadata">

**Author:** ![ab1](https://avatars.discourse-cdn.com/v4/letter/a/d2c977/32.png) [@ab1](https://forums.suse.com/u/ab1)\
**Post date:** [September 20, 2018, 7:24am UTC](https://forums.suse.com/t/postgres-data-directory-in-sles11/32942/2 "2018-09-20T07:24:48Z")

</div>

On 09/19/2018 01:04 PM, mlino wrote:[color=blue]

> I have installed Postgresql94 using zypper and I would like to change  
> the data directory. I alraedy have a database, so I would like to  
> migrate it to the new location and then change the location in the  
> postgresql configuration.[/color]

That sounds reasonable, assuming by “migrate it to the new location” you  
mean something like the following:

1. Stop the PostgreSQL service.
2. Move the files to the new location.
3. Update the configuration to point to the new location.
4. Start the PostgreSQL service.  
[color=blue]

> I Have tried to make the change, but I was unable to manage to restart  
> postgres server again.[/color]

How, in annoying detail, did you try this, and what specific symptoms do  
you have of failure? The more details you can provide the better,  
including configuration files (like for PostgreSQL), log file output, etc.

–  
Good luck.

If you find this post helpful and are logged into the web interface,  
show your appreciation and click on the star below.

If you want to send me a private message, please let me know in the  
forum as I do not use the web interface often.

---

<div class="post-metadata">

**Author:** ![mlino](https://avatars.discourse-cdn.com/v4/letter/m/a5b964/32.png) [@mlino](https://forums.suse.com/u/mlino)\
**Post date:** [September 20, 2018, 3:54pm UTC](https://forums.suse.com/t/postgres-data-directory-in-sles11/32942/3 "2018-09-20T15:54:55Z")

</div>

Hi and thank you.  
[QUOTE=ab;54488]On 09/19/2018 01:04 PM, mlino wrote:[color=blue]

> I have installed Postgresql94 using zypper and I would like to change  
> the data directory. I alraedy have a database, so I would like to  
> migrate it to the new location and then change the location in the  
> postgresql configuration.[/color]

That sounds reasonable, assuming by “migrate it to the new location” you  
mean something like the following:

1. Stop the PostgreSQL service.
2. Move the files to the new location.
3. Update the configuration to point to the new location.
4. Start the PostgreSQL service.

[color=red]  
I followed the exact steps you listed above, but the server doesn’t start in the new location. I got an error in the postgresql-init script, related to the new location of the files.

[/color]

[color=blue]

> I Have tried to make the change, but I was unable to manage to restart  
> postgres server again.[/color]

How, in annoying detail, did you try this, and what specific symptoms do  
you have of failure? The more details you can provide the better,  
including configuration files (like for PostgreSQL), log file output, etc.

[color=red]  
I stopped the server the I did a copy for the new location using rsync

rsync -av -o -g /var/lib/pgsql/ /dados/pgsql

Then I changed the location of the files in /etc/sysconfig/postgresql pointing to the new location. I have left the new location commented as you can see bellow.

## Path: Applications/PostgreSQL

## Description: The PostgreSQL Database System

## Type: string()

## Default: “~postgres/data”

## ServiceRestart: postgresql

# 

# In which directory should the PostgreSQL database reside?

# 

POSTGRES\_DATADIR=“~postgres/data”  
#POSTGRES\_DATADIR=“/dados/pgsql/data”

After that, I tried to restart the server and it doesn’t start due to an error in the postgresql-init script. Then I tried to fix the error but I didn’t figure out what was happening so I decided to rollback the changes.

This is the content of the /dados/pgsql

[FONT=Courier New][SIZE=3]  
-rwxr-x— 1 postgres postgres 8851 Sep 19 17:37 .bash\_history  
drwxr-x— 3 postgres postgres 4096 Sep 19 15:06 .local  
-rwxr-x— 1 postgres postgres 1314 Sep 19 15:06 .psql\_history  
-rwxr-x— 1 postgres postgres 600 Sep 19 15:06 .viminfo  
-rw-r–r-- 1 postgres postgres 4947 Sep 19 16:25 .y2log  
-rwxr-x— 1 postgres postgres 4 Sep 19 15:06 PG\_VERSION  
drwx------ 8 postgres postgres 4096 Sep 19 15:06 base  
drwxr-xr-x 3 postgres postgres 4096 Sep 19 17:41 dados  
drwx------ 19 postgres postgres 4096 Sep 19 17:52 data  
drwx------ 2 postgres postgres 4096 Sep 19 15:06 global  
-rwxr-x— 1 postgres postgres 1341 Sep 19 17:44 initlog  
-rwxr-x— 1 postgres postgres 1058 Sep 19 15:06 logfile  
drwx------ 2 postgres postgres 4096 Sep 19 15:06 pg\_clog  
drwx------ 2 postgres postgres 4096 Sep 19 15:06 pg\_dynshmem  
-rwxr-x— 1 postgres postgres 4517 Sep 19 15:06 pg\_hba.conf  
-rwxr-x— 1 postgres postgres 1636 Sep 19 15:06 pg\_ident.conf  
drwx------ 2 postgres postgres 4096 Sep 19 15:06 pg\_log  
drwx------ 4 postgres postgres 4096 Sep 19 15:06 pg\_logical  
drwx------ 4 postgres postgres 4096 Sep 19 15:06 pg\_multixact  
drwx------ 2 postgres postgres 4096 Sep 19 15:06 pg\_notify  
drwx------ 2 postgres postgres 4096 Sep 19 15:06 pg\_replslot  
drwx------ 2 postgres postgres 4096 Sep 19 15:06 pg\_serial  
drwx------ 2 postgres postgres 4096 Sep 19 15:06 pg\_snapshots  
drwx------ 2 postgres postgres 4096 Sep 19 15:06 pg\_stat  
drwx------ 2 postgres postgres 4096 Sep 19 15:06 pg\_stat\_tmp  
drwx------ 2 postgres postgres 4096 Sep 19 15:06 pg\_subtrans  
drwx------ 2 postgres postgres 4096 Sep 19 15:06 pg\_tblspc  
drwx------ 2 postgres postgres 4096 Sep 19 15:06 pg\_twophase  
drwx------ 3 postgres postgres 4096 Sep 19 15:06 pg\_xlog  
-rwxr-x— 1 postgres postgres 88 Sep 19 15:06 postgresql.auto.conf  
-rwxr-x— 1 postgres postgres 20860 Sep 19 15:06 postgresql.conf  
-rwxr-x— 1 postgres postgres 57 Sep 19 15:06 postmaster.opts[/SIZE][/FONT]

[/color]

## Thank you.

Good luck.

If you find this post helpful and are logged into the web interface,  
show your appreciation and click on the star below.

If you want to send me a private message, please let me know in the  
forum as I do not use the web interface often.[/QUOTE]

---

<div class="post-metadata">

**Author:** ![ab1](https://avatars.discourse-cdn.com/v4/letter/a/d2c977/32.png) [@ab1](https://forums.suse.com/u/ab1)\
**Post date:** [September 20, 2018, 5:06pm UTC](https://forums.suse.com/t/postgres-data-directory-in-sles11/32942/4 "2018-09-20T17:06:35Z")

</div>

On 09/20/2018 07:04 AM, mlino wrote:[color=blue]

> [color=green]
> 
> > I stopped the server the I did a copy for the new location using rsync
> > 
> > rsync -av -o -g /var/lib/pgsql/ /dados/pgsql[/color][/color]

rsync is awesome.  
[color=blue][color=green]

> > Then I changed the location of the files in /etc/sysconfig/postgresql  
> > pointing to the new location. I have left the new location commented as  
> > you can see bellow.[/color][/color]

I presume before you rolled back you did not have the new location  
commented out. Thanks for not just removing it; that was a good idea.  
[color=blue][color=green]

> > POSTGRES\_DATADIR=“~postgres/data”  
> > #POSTGRES\_DATADIR=“/dados/pgsql/data”
> > 
> > After that, I tried to restart the server and it doesn’t start due to an  
> > error in the postgresql-init script. Then I tried to fix the error but I  
> > didn’t figure out what was happening so I decided to rollback the  
> > changes.[/color][/color]

What is the exact, copied/pasted, error? Also, after you modified the  
/etc/sysconfig file did you do anything else? Some of those files need to  
have you run SuSEconfig (maybe that’s only in the old days) command to  
have those variables get copied to the right places, e.g. to the actual  
init scripts, or conf files, or service units (SLES 12+), which actually  
do the work. /etc/sysconfig has a lot of great data, but it is made for  
administration tools more than for actual applications managed by those  
tools, so my concern is that the PostgreSQL startup code may not be  
looking there, though I do not have a system to check right now.

Let’s just start with the exact error message. If you want to get a lot  
of great output, prepend the init script with 'bash -xv ’ so we can see  
all of the evaluation of variables, etc. in that script. It may help us  
figure out if a variable is not changing properly.

–  
Good luck.

If you find this post helpful and are logged into the web interface,  
show your appreciation and click on the star below.

If you want to send me a private message, please let me know in the  
forum as I do not use the web interface often.

---

<div class="post-metadata">

**Author:** ![mlino](https://avatars.discourse-cdn.com/v4/letter/m/a5b964/32.png) [@mlino](https://forums.suse.com/u/mlino)\
**Post date:** [September 20, 2018, 6:04pm UTC](https://forums.suse.com/t/postgres-data-directory-in-sles11/32942/5 "2018-09-20T18:04:10Z")

</div>

Hi, bellow is what I have tried minutes ago (in red)

[QUOTE=ab;54497]On 09/20/2018 07:04 AM, mlino wrote:[color=blue]

> [color=green]
> 
> > I stopped the server the I did a copy for the new location using rsync
> > 
> > rsync -av -o -g /var/lib/pgsql/ /dados/pgsql[/color][/color]

rsync is awesome.  
[color=blue][color=green]

> > Then I changed the location of the files in /etc/sysconfig/postgresql  
> > pointing to the new location. I have left the new location commented as  
> > you can see bellow.[/color][/color]

I presume before you rolled back you did not have the new location  
commented out. Thanks for not just removing it; that was a good idea.  
[color=blue][color=green]

> > POSTGRES\_DATADIR=“~postgres/data”  
> > #POSTGRES\_DATADIR=“/dados/pgsql/data”
> > 
> > After that, I tried to restart the server and it doesn’t start due to an  
> > error in the postgresql-init script. Then I tried to fix the error but I  
> > didn’t figure out what was happening so I decided to rollback the  
> > changes.[/color][/color]

What is the exact, copied/pasted, error?

[color=red]  
I don’t remember that. Was something related to the pg\_ctl initdb..  
[/color]

Also, after you modified the  
/etc/sysconfig file did you do anything else? Some of those files need to  
have you run SuSEconfig (maybe that’s only in the old days) command to  
have those variables get copied to the right places, e.g. to the actual  
init scripts, or conf files, or service units (SLES 12+), which actually  
do the work. /etc/sysconfig has a lot of great data, but it is made for  
administration tools more than for actual applications managed by those  
tools, so my concern is that the PostgreSQL startup code may not be  
looking there, though I do not have a system to check right now.

Let’s just start with the exact error message. If you want to get a lot  
of great output, prepend the init script with 'bash -xv ’ so we can see  
all of the evaluation of variables, etc. in that script. It may help us  
figure out if a variable is not changing properly.

[color=red]  
I stopped the server minutes ago and change the DATADIR to the following:

POSTGRES\_DATADIR=“./dados/pgsql/data”

Then I restarted the server and it goes up and running. Even with server up and runnign I cannot connect due to the following error:

Unable to connect to server:could not connect to server: Connection refused (0x0000274D/10061).

## In pgAdmin the server stays asking for postgres user password, and even with the correct password I cannot get access to it. [/color]

Good luck.

If you find this post helpful and are logged into the web interface,  
show your appreciation and click on the star below.

If you want to send me a private message, please let me know in the  
forum as I do not use the web interface often.[/QUOTE]

---

<div class="post-metadata">

**Author:** ![Jens-U](https://avatars.discourse-cdn.com/v4/letter/j/d78d45/32.png) [@Jens-U](https://forums.suse.com/u/Jens-U)\
**Post date:** [September 20, 2018, 6:19pm UTC](https://forums.suse.com/t/postgres-data-directory-in-sles11/32942/6 "2018-09-20T18:19:02Z")

</div>

Hi mlino,

while it may appear to be some sort of “chicken exit”, have you thought about symlinking instead of redefining per config? So that ~postgres/data is a symlink to /dados/pgsql/data and everything else stays the same?

Regards,  
J
