Thread: Problem. createdb: could not connect to database postgres: could not connect to server: No such file or directory

Hai, I use Debian Etch. I have a problem with postgresql 8.1. I have uninstalled the postgresql-8.3, which I was took from debian back ports, removed its configuration files, and the user postgres also. Then installed postgresql-8.1. But when I started to create a database, it shows some message like this..
Here is the output I got:-
-----------------------------------------------------
localhost:/home/user# su - postgres
postgres@localhost:~$ /usr/lib/postgresql/8.1/bin/initdb -D /var/lib/postgresql/data
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 en_IN.
The default database encoding has accordingly been set to UTF8.

initdb: directory "/var/lib/postgresql/data" exists but is not empty
If you want to create a new database system, either remove or empty
the directory "/var/lib/postgresql/data" or run initdb
with an argument other than "/var/lib/postgresql/data".
postgres@localhost:~$ /usr/lib/postgresql/8.1/bin/pg_ctl -D /var/lib/postgresql/data -l logfile start
postmaster starting
postgres@localhost:~$ /usr/lib/postgresql/8.1/bin/createdb test
createdb: could not connect to database postgres: could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
postgres@localhost:~$
-----------------------------------------------------
Why it can't connect to server? How can I resolve it??

--
(`'·.¸(`'·.¸  ¸.·'´) ¸.·'´)  
«´¨`·*Jaisen.*..´¨`»
(¸.·'´(¸.·'´   `'·.¸)`'·.¸)
¸.·´
(  `·.¸  
`·.¸ )
¸.·)´  
(.·´    
( `v´ )
  `v´
Jaisen N.D. wrote:
> Hai, I use Debian Etch. I have a problem with postgresql 8.1. I have
> uninstalled the postgresql-8.3, which I was took from debian back ports,
> removed its configuration files, and the user postgres also.
It sounds like you didn't remove the data directory,
/var/lib/postgresql/data .

By the way, if you want to remove all configuration etc along with a
package you should use apt-get --purge remove .
> initdb: directory "/var/lib/postgresql/data" exists but is not empty
> If you want to create a new database system, either remove or empty
> the directory "/var/lib/postgresql/data" or run initdb
> with an argument other than "/var/lib/postgresql/data".
>
initdb could not create a database cluster because there were files in
/var/lib/postgresql/data . You should rename the `data' directory to
something else or remove it. Removing it will destroy your database.

PostgreSQL 8.1 cannot read data from PostgreSQL 8.3 .

> postgres@localhost:~$ /usr/lib/postgresql/8.1/bin/pg_ctl -D
> /var/lib/postgresql/data -l logfile start
> postmaster starting
>
If you have a look at the postgresql logs you will see that postgresql
failed to start because it cannot read the data in the data directory;
it is for the wrong version of postgresql.

--
Craig Ringer

On Apr 12, 2008, at 7:11 AM, Jaisen N.D. wrote:
> localhost:/home/user# su - postgres
> postgres@localhost:~$ /usr/lib/postgresql/8.1/bin/initdb -D /var/
> lib/postgresql/data
> 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 en_IN.
> The default database encoding has accordingly been set to UTF8.
>
> initdb: directory "/var/lib/postgresql/data" exists but is not empty
> If you want to create a new database system, either remove or empty
> the directory "/var/lib/postgresql/data" or run initdb
> with an argument other than "/var/lib/postgresql/data".

It says right here. You forgot to move your old data directory out of
the way. As it's from a Postgres 8.3 installation, Postgres 8.1 has
no way of knowing how to handle what's in there.

> postgres@localhost:~$ /usr/lib/postgresql/8.1/bin/pg_ctl -D /var/
> lib/postgresql/data -l logfile start
> postmaster starting
> postgres@localhost:~$ /usr/lib/postgresql/8.1/bin/createdb test
> createdb: could not connect to database postgres: could not connect
> to server: No such file or directory
>         Is the server running locally and accepting
>         connections on Unix domain socket "/var/run/
> postgresql/.s.PGSQL.5432"?
> postgres@localhost:~$
> -----------------------------------------------------
> Why it can't connect to server? How can I resolve it??


Because initialisation of the database (initdb) failed for the
aforementioned reason. There are probably some messages in your logs
about postgres failing to start or to operate on its data directory.
You can't just run a different major version of postgres on an
existing data directory.

You didn't tell what your goal is. Are you trying to downgrade an
existing database? If so, why would you want to do that?

Alban Hertroys

--
If you can't see the forest for the trees,
cut the trees and you'll see there is no forest.


!DSPAM:737,48008eed927663372713408!



Hi., Sorry for my late reply, I wasn't on desk for last few days. My goal is to set up a spatial database, with postgresql 8.1. I removed the postgresql installation using apt-get --purge remove. and removed the var/lib/postgresql/data directory. And then reinstalled it again. The result I got is here:-
--------------------------
localhost:/home/user# apt-get install postgresql-8.1
Reading package lists... Done
Building dependency tree... Done
The following extra packages will be installed:
  postgresql-client-8.1
The following NEW packages will be installed:
  postgresql-8.1 postgresql-client-8.1
0 upgraded, 2 newly installed, 0 to remove and 1 not upgraded.
Need to get 0B/5711kB of archives.
After unpacking 15.1MB of additional disk space will be used.
Do you want to continue [Y/n]? y
Selecting previously deselected package postgresql-client-8.1.
(Reading database ... 197573 files and directories currently installed.)
Unpacking postgresql-client-8.1 (from .../postgresql-client-8.1_8.1
.11-0etch1_i3 86.deb) ...
Selecting previously deselected package postgresql-8.1.
Unpacking postgresql-8.1 (from .../postgresql-8.1_8.1.11-0etch1_i386.deb) ...
Setting up postgresql-client-8.1 (8.1.11-0etch1) ...

Setting up postgresql-8.1 (8.1.11-0etch1) ...
Creating new cluster (configuration: /etc/postgresql/8.1/main, data: /var/lib/po stgresql/8.1/main)...
Moving configuration file /var/lib/postgresql/8.1/main/postgresql.conf to /etc/p ostgresql/8.1/main...
Moving configuration file /var/lib/postgresql/8.1/main/pg_hba.conf to /etc/postg resql/8.1/main...
Moving configuration file /var/lib/postgresql/8.1/main/pg_ident.conf to /etc/pos tgresql/8.1/main...
Warning: The socket directory for owners other than 'postgres'
defaults to /tmp. You might want to change the unix_socket_directory parameter
in postgresql.conf to a more secure directory.
Configuring postgresql.conf to use port 5432...
Starting PostgreSQL 8.1 database server: main.

localhost:/home/user#
--------------------------------------
I created data folder again. But When I tried to create a test database, I couldn't. Here is the steps I followed:-
--------------------------------------
localhost:/home/user# adduser postgres
adduser: The user `postgres' already exists.
localhost:/home/user# mkdir /var/lib/postgresql/data
localhost:/home/user# chown postgres /var/lib/postgresql/data
localhost:/home/user# su - postgres
postgres@localhost:~$ /usr/lib/postgresql/8.1/bin/initdb -D /var/lib/postgresql/data
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 en_IN.
The default database encoding has accordingly been set to UTF8.

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/pg_twophase ... ok
creating directory /var/lib/postgresql/data/pg_multixact/members ... ok
creating directory /var/lib/postgresql/data/pg_multixact/offsets ... 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_authid ... ok
enabling unlimited row size for system tables ... ok
initializing dependencies ... 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
copying template1 to postgres ... 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/lib/postgresql/8.1/bin/postmaster -D /var/lib/postgresql/data
or
    /usr/lib/postgresql/8.1/bin/pg_ctl -D /var/lib/postgresql/data -l logfile start

postgres@localhost:~$ /usr/lib/postgresql/8.1/bin/pg_ctl -D /var/lib/postgresql/data -l logfile start
postmaster starting
postgres@localhost:~$ /usr/lib/postgresql/8.1/bin/createdb test
createdb: could not connect to database postgres: could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
postgres@localhost:~$
--------------------------------------
Where is the problem??
The logfile in home folder of postgres user is as follows:-
--------------------------------------
 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:  could not create any TCP/IP sockets
    ----------------------------------------
How can I correct it??

--
(`'·.¸(`'·.¸  ¸.·'´) ¸.·'´)  
«´¨`·*Jaisen.*..´¨`»
(¸.·'´(¸.·'´   `'·.¸)`'·.¸)
¸.·´
(  `·.¸  
`·.¸ )
¸.·)´  
(.·´    
( `v´ )
  `v´
On Sat, Apr 19, 2008 at 10:14:00AM +0530, Jaisen N.D. wrote:
> Hi., Sorry for my late reply, I wasn't on desk for last few days. My goal is
> to set up a spatial database, with postgresql 8.1. I removed the postgresql
> installation using apt-get --purge remove. and removed the
> var/lib/postgresql/data directory. And then reinstalled it again. The result
> I got is here:-

Why are you creating a database here:
> --------------------------------------
> I created data folder again. But When I tried to create a test database, I
> couldn't. Here is the steps I followed:-
> --------------------------------------
> localhost:/home/user# adduser postgres
> adduser: The user `postgres' already exists.
> localhost:/home/user# mkdir /var/lib/postgresql/data
> localhost:/home/user# chown postgres /var/lib/postgresql/data
> localhost:/home/user# su - postgres

When it told you it already created one and it's already running.
> Creating new cluster (configuration: /etc/postgresql/8.1/main, data:
> /var/lib/po stgresql/8.1/main)...

<snip>

> Configuring postgresql.conf to use port 5432...
> Starting PostgreSQL 8.1 database server: main.

Delete directory just created and do this as root:

su - postgres
createuser <your username>
# Say you wanto to be superuser
createdb <database name>

> Where is the problem??
> The logfile in home folder of postgres user is as follows:-
> --------------------------------------
>  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.

Use the server already running, instead of making another one.

Have a nice day,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Please line up in a tree and maintain the heap invariant while
> boarding. Thank you for flying nlogn airlines.

Attachment