# postgres user can get really borked 70:70 not 1000:1000?

## turtles

EDITED FOR CLARITY (I hope):

I have been trying to reinstall postgresql for 3 days. (my original install went great just did not have a php extension) It sems the 'postgresql ebuild' or 'base layout' has to create the user postgres during install for permissions, shell, directory to be correct. However somthing was not created properly by ebuild or baselayout? This is repeatable as I have completly removed postgresql 

```
emerge -C postgresql
```

and the user postgres 

```
userdel postgres
```

and started over. I have searched and found bugs that might be related: https://bugs.gentoo.org/show_bug.cgi?id=79142

https://bugs.gentoo.org/show_bug.cgi?id=96294

https://bugs.gentoo.org/show_bug.cgi?id=128291

ON the second install I had the same problem as 

this solved post. It sounded weird but it is marked solved and said to delete the user postgres, so i did and the fun began....... (scroll down to the last post to see where I am)

```
/etc/init.d/postgresql start

 * Starting PostgreSQL ...

No directory, logging in with HOME=/

 * Please see log file: /var/lib/postgresql/data/postgresql.log
```

 the contents of the log file are 

```
FATAL:  could not open lock file "/tmp/.s.PGSQL.5432.lock": Permission denied
```

 at this point i have lost all my sql-ledger setup (no actual data) to reinsatll postgresql:

```
accordian etc # emerge --config =postgresql-8.0.8

Configuring pkg...

 * Creating the data directory ...

 * Initializing the database ...

 * Postgres 8.0.8 cannot upgrade your existing databases      .

 * You must remove your entire database directory to con      tinue.

 * (database directory = /var/lib/postgresql).

accordian etc # rm /var/lib/postgresql

```

 and It runs fine but when I start postgresql I get the same error after all that.

```
 ls -la /tmp/.s.PGSQL.5432.lock

-rw------- 1 70 70 31 Jul 22 19:59 /tmp/.s.PGSQL.5432.lock

```

the info from etc/passwd is:

```
postgres:x:1000:1000::/home/postgres:/bin/bash
```

----------

## turtles

I no longer had a directory /home/postgres so I created one

and I obviously

```
chown postgres:postgres /tmp/.s.PGSQL.5432.lock

```

and postgres started but is this all?

why did all this happen in the first place?

----------

## turtles

still getting permission denied everywhere

```
postgres@accordian /root $ createlang plpgsql template1

could not change directory to "/root"

createlang: could not connect to database template1: could not connect to server: Connection refused

        Is the server running locally and accepting

        connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

postgres@accordian /root $ ls

ls: .: Permission denied

postgres@accordian /root $         
```

then I tried

```
accordian ~ # chown -R postgres:postgres /home/postgres/

accordian ~ # su postgres

postgres@accordian /root $ createlang plpgsql template1

could not change directory to "/root"

createlang: could not connect to database template1: could not connect to server: Connection refused

        Is the server running locally and accepting

        connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

```

It takes a long time to stop but will stop and restart

```
accordian ~ # /etc/init.d/postgresql stop

 * Stopping PostgreSQL ...

postmaster stopped                                      [ ok ]

accordian ~ # /etc/init.d/postgresql start

 * Starting PostgreSQL ...                              [ ok ]

accordian ~ # su postgres

postgres@accordian /root $ createlang plpgsql template1

could not change directory to "/root"

createlang: could not connect to database template1: could not connect to server: Connection refused

        Is the server running locally and accepting

        connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

postgres@accordian /root $ ls

ls: .: Permission denied

```

 It wont even let me ls?

EDIT: So I have done a few hours of searching around 

and found a few things

```
accordian data # /etc/init.d/postgresql stop

 * Stopping PostgreSQL ...

pg_ctl: PID file "/var/lib/postgresql/data/postmaster.pid" does not exist

Is postmaster running?                                                                                                              [ !! ]

accordian data # /etc/init.d/postgresql zap

 * Manually resetting postgresql to stopped state.

accordian data # ps -la

F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD

4 S     0  6441  6417  0  78   0 -   840 read_c tty1     00:00:00 bash

4 S     0  1092 28288  3  76   0 -  5525 wait   pts/1    00:05:45 emerge

0 S  1000 17796     1  0  76   0 -  4984 select pts/0    00:00:01 postmaster

1 S  1000 17800 17796  0  76   0 -  4984 select pts/0    00:00:00 postmaster

1 S  1000 17801 17796  0  76   0 -  2701 select pts/0    00:00:00 postmaster

1 S  1000 17802 17801  0  76   0 -  2495 select pts/0    00:00:00 postmaster

4 S     0  9158  1092  0  79   0 -   430 pipe_w pts/1    00:00:00 tee

0 S     0  9159  1092  0  78   0 -   445 wait   pts/1    00:00:00 sandbox

0 S     0  9160  9159  0  83   0 -  1557 wait   pts/1    00:00:03 ebuild.sh

0 S     0 10292  9160  0  78   0 -   890 wait   pts/1    00:00:00 make

0 S     0  4023 10292  0  85   0 -   914 wait   pts/1    00:00:00 sh

0 S     0  4060  4023  0  85   0 -  1249 wait   pts/1    00:00:00 make

0 S     0  4106  4060  0  79   0 -  1349 pipe_w pts/1    00:00:02 make

0 S     0  5186  4106  0  77   0 -   614 wait   pts/1    00:00:00 gcc

0 S     0  5191  5186  0  80   0 -   638 wait   pts/1    00:00:00 gcc

0 R     0  5192  5191 46  85   0 -  6428 -      pts/1    00:00:07 cc1

0 S     0  5208  4106  0  77   0 -   614 wait   pts/1    00:00:00 gcc

0 S     0  5225  5208  0  80   0 -   636 wait   pts/1    00:00:00 gcc

0 R     0  5226  5225 47  85   0 -  5611 -      pts/1    00:00:05 cc1

4 R     0  5227  6462  0  77   0 -   559 -      pts/0    00:00:00 ps

accordian data # kill 17796

accordian data # kill 17800

-bash: kill: (17800) - No such process

accordian data # ps -la

F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD

4 S     0  6441  6417  0  78   0 -   840 read_c tty1     00:00:00 bash

4 S     0  1092 28288  3  76   0 -  5525 wait   pts/1    00:05:45 emerge

4 S     0  9158  1092  0  79   0 -   430 pipe_w pts/1    00:00:00 tee

0 S     0  9159  1092  0  78   0 -   445 wait   pts/1    00:00:00 sandbox

0 S     0  9160  9159  0  83   0 -  1557 wait   pts/1    00:00:03 ebuild.sh

0 S     0 10292  9160  0  78   0 -   890 wait   pts/1    00:00:00 make

0 S     0  4023 10292  0  85   0 -   914 wait   pts/1    00:00:00 sh

0 S     0  4060  4023  0  85   0 -  1249 wait   pts/1    00:00:00 make

0 S     0  4106  4060  0  79   0 -  1382 pipe_w pts/1    00:00:02 make

0 S     0  5283  4106  0  76   0 -   614 wait   pts/1    00:00:00 gcc

0 S     0  5286  5283  0  80   0 -   638 wait   pts/1    00:00:00 gcc

0 R     0  5287  5286 46  85   0 -  4352 -      pts/1    00:00:01 cc1

0 S     0  5289  4106  1  77   0 -   614 wait   pts/1    00:00:00 gcc

0 S     0  5292  5289  2  80   0 -   636 wait   pts/1    00:00:00 gcc

0 R     0  5293  5292  0  81   0 -  2490 -      pts/1    00:00:00 cc1

4 R     0  5294  6462  0  77   0 -   559 -      pts/0    00:00:00 ps

accordian data # /etc/init.d/postgresql start

 * Starting PostgreSQL ...                                                                                                          [ ok ]

accordian data # ps -la

F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD

4 S     0  6441  6417  0  78   0 -   840 read_c tty1     00:00:00 bash

4 S     0  1092 28288  3  76   0 -  5525 wait   pts/1    00:05:45 emerge

4 S     0  9158  1092  0  79   0 -   430 pipe_w pts/1    00:00:00 tee

0 S     0  9159  1092  0  78   0 -   445 wait   pts/1    00:00:00 sandbox

0 S     0  9160  9159  0  83   0 -  1557 wait   pts/1    00:00:03 ebuild.sh

0 S     0 10292  9160  0  78   0 -   890 wait   pts/1    00:00:00 make

0 S     0  4023 10292  0  85   0 -   914 wait   pts/1    00:00:00 sh

0 S     0  4060  4023  0  85   0 -  1249 wait   pts/1    00:00:00 make

0 S     0  4106  4060  0  79   0 -  1415 pipe_w pts/1    00:00:02 make

0 S     0  5308  4106  0  76   0 -   614 wait   pts/1    00:00:00 gcc

0 S     0  5311  5308  0  80   0 -   638 wait   pts/1    00:00:00 gcc

0 R     0  5312  5311 44  85   0 -  7936 -      pts/1    00:00:11 cc1

0 S     0  5314  4106  0  77   0 -   614 wait   pts/1    00:00:00 gcc

0 S     0  5317  5314  0  80   0 -   636 wait   pts/1    00:00:00 gcc

0 R     0  5318  5317 45  85   0 -  7033 -      pts/1    00:00:09 cc1

0 S  1000  5375     1 16  76   0 -  4984 select pts/0    00:00:00 postmaster

1 S  1000  5378  5375  0  76   0 -  4984 select pts/0    00:00:00 postmaster

1 S  1000  5379  5375  0  76   0 -  2701 select pts/0    00:00:00 postmaster

1 S  1000  5380  5379  0  76   0 -  2495 select pts/0    00:00:00 postmaster

4 R     0  5381  6462  0  78   0 -   559 -      pts/0    00:00:00 ps

accordian data # su postgres -

postgres@accordian /var/lib/postgresql/data $ createuser -d sql-ledger

Shall the new user be allowed to create more new users? (y/n) y

createuser: could not connect to database template1: could not connect to server: Connection refused

        Is the server running locally and accepting

        connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

postgres@accordian /var/lib/postgresql/data $                             
```

```

File: postgresql.log

LOG:  could not bind IPv4 socket: Address already in use

HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.

WARNING:  could not create listen socket for "localhost"

FATAL:  lock file "/tmp/.s.PGSQL.5432.lock" already exists

HINT:  Is another postmaster (PID 17796) using socket file "/tmp/.s.PGSQL.5432"?

LOG:  could not bind Unix socket: Address already in use

HINT:  Is another postmaster already running on port 5432? If not, remove socket file "/tmp/.s.PGSQL.5432" and retry.

WARNING:  could not create Unix-domain socket

LOG:  database system was shut down at 2006-07-23 01:40:35 PDT

LOG:  checkpoint record is at 0/ABEA90

LOG:  redo record is at 0/ABEA90; undo record is at 0/0; shutdown TRUE

LOG:  next transaction ID: 544; next OID: 17230

LOG:  database system is ready

```

I sincerely hope this is a just simple noob mistake on my part!

```
emerge -C postgreesql
```

```
userdel postgres
```

```
rm -R /home/postgres
```

```
emerge postgresql
```

----------

## turtles

OK http://www.gentoo.org/doc/en/postgres-howto.xml

 emerge completed

```
 * Make sure the postgres user in /etc/passwd has an account s      etup with /bin/bash as the shell

>>> Regenerating /etc/ld.so.cache...

>>> dev-db/postgresql-8.0.8 merged.

>>> Recording dev-db/postgresql in "world" favorites file...

>>> No packages selected for removal by clean.

>>> Auto-cleaning packages...

>>> No outdated packages were found on your system.

 * GNU info directory index is up-to-date.

```

checking etc/passwd

```
postgres:x:70:70:added by portage for postgresql:/var/lib/postgresql:/bin/bash
```

OK

```
passwd: password updated successfully
```

OK

```
emerge --config =postgresql-8.0.8

Configuring pkg...

 * Creating the data directory ...

 * Initializing the database ...

 * Postgres 8.0.8 cannot upgrade your existing databases.

 * You must remove your entire database directory to continue.

 * (database directory = /var/lib/postgresql).

accordian ~ # rm -R /var/lib/postgresql/

```

Hmmm

```
emerge --config =postgresql-8.0.8

Configuring pkg...

 * Creating the data directory ...

 * Initializing the database ...

The files belonging to this database system will be owned by user "postgres".

This user must also own the server process.

The database cluster will be initialized with locale C.

fixing permissions on existing directory /var/lib/postgresql/data ... ok

creating directory /var/lib/postgresql/data/global ... ok

creating directory /var/lib/postgresql/data/pg_xlog ... ok

creating directory /var/lib/postgresql/data/pg_xlog/archive_status ... ok

creating directory /var/lib/postgresql/data/pg_clog ... ok

creating directory /var/lib/postgresql/data/pg_subtrans ... ok

creating directory /var/lib/postgresql/data/base ... ok

creating directory /var/lib/postgresql/data/base/1 ... ok

creating directory /var/lib/postgresql/data/pg_tblspc ... ok

selecting default max_connections ... 100

selecting default shared_buffers ... 1000

creating configuration files ... ok

creating template1 database in /var/lib/postgresql/data/base/1 ... ok

initializing pg_shadow ... ok

enabling unlimited row size for system tables ... ok

initializing pg_depend ... ok

creating system views ... ok

loading pg_description ... ok

creating conversions ... ok

setting privileges on built-in objects ... ok

creating information schema ... ok

vacuuming database template1 ... ok

copying template1 to template0 ... ok

WARNING: enabling "trust" authentication for local connections

You can change this by editing pg_hba.conf or using the -A option the

next time you run initdb.

Success. You can now start the database server using:

    /usr/bin/postmaster -D /var/lib/postgresql/data

or

    /usr/bin/pg_ctl -D /var/lib/postgresql/data -l logfile start

 *

 * You can use /etc/init.d/postgresql script to run PostgreSQL instead of pg_ctl.

 *

```

OK 

```
/etc/init.d/postgresql start

 * Caching service dependencies ...                           [ ok ]

 * Starting PostgreSQL ...                                    [ ok ]

accordian ~ #             
```

better

```
postgres@accordian /root $ createuser -d -P sql-ledger

could not change directory to "/root"

Enter password for new user:

Enter it again:

Shall the new user be allowed to create more new users? (y/n) y

CREATE USER

```

OK it works after all that, but why all the effort what did I do wrong originaly?

could this have been solved without all the hassle?

When I had all the problems I had

When I had the problem I had   

```
postgres:x:1000:1000::/home/postgres:/bin/bash
```

now I have  

```
postgres:x:70:70:added by portage for postgresql:/var/lib/postgresql:/bin/bash
```

what is the 70:70 and the 1000:1000?

----------

## turtles

Still getting could not change to /root errors.

----------

## MickKi

A year has almost gone by . . .

I followed the Gentoo guide for PostgreSQL.  When I try to create a passwd I get this much:

```
# passwd postgres

passwd: Authentication token manipulation error
```

 Why is this and how can I fix it?

I can see that in my /etc/passwd:

```
# less /etc/passwd | grep postgres

postgres:x:70:70::/var/lib/postgresql:/bin/bash
```

In /etc/shadow there's no relevant file!:

```
less /etc/shadow | grep postgres
```

pwck gives me this:

```
# pwck | grep postgres

user postgres: directory /var/lib/postgresql does not exist
```

 What the . . . ?!

In /etc/group I have:

```
# less /etc/group | grep postgres 

postgres:x:70:
```

What is the correct fix for this?

----------

## MickKi

OK, the correct way to fix this according to Bug No 98406 is to run as root:

```
# /usr/sbin/pwconv postgres
```

  Thereafter the Authentication token manipulation error does not happen anymore, hurray!  Shouldn't both the documentation and the ebuild tell us so?

----------

