How do I create a database if I can't connect to it?

Started by Paolo Victorover 18 years ago8 messagesgeneral
Jump to latest
#1Paolo Victor
paolovictor@gmail.com

Hello,

For a short description, I'll just show the sequence of commands I'm trying
to execute:

paolo@box> initdb -D /usr/local/pgsql/data/
paolo@box> postgres -D /usr/local/pgsql/data -i -p 5435
paolo@box> createdb foo -p 5435
createdb: could not connect to database foo: FATAL: database "foo" does not
exist

And

"postgres -D /usr/local/pgsql/data -i -p 5435"'s output:

/*
LOG: database system was shut down at 2007-07-27 11:25:27 BRT
LOG: checkpoint record is at 0/42C4B4
LOG: redo record is at 0/42C4B4; undo record is at 0/0; shutdown TRUE
LOG: next transaction ID: 0/593; next OID: 10820
LOG: next MultiXactId: 1; next MultiXactOffset: 0
LOG: database system is ready
FATAL: database "foo" does not exist
*/

Now, am I doing something terribly wrong/noobish, or Postgres is freaking
out because I want to create a database that does not exist?

Thanks in advance,
~Paolo

#2David Fetter
david@fetter.org
In reply to: Paolo Victor (#1)
Re: How do I create a database if I can't connect to it?

On Fri, Jul 27, 2007 at 11:28:58AM -0300, Paolo Victor wrote:

Hello,

For a short description, I'll just show the sequence of commands I'm trying
to execute:

paolo@box> initdb -D /usr/local/pgsql/data/

This looks like a mistake. Unless you plan to develop the PostgreSQL
code itself, you should not be installing from source. Instead, you
should be using one from the packaging system your operating system
uses.

paolo@box> postgres -D /usr/local/pgsql/data -i -p 5435
paolo@box> createdb foo -p 5435
createdb: could not connect to database foo: FATAL: database "foo" does not
exist

And

"postgres -D /usr/local/pgsql/data -i -p 5435"'s output:

/*
LOG: database system was shut down at 2007-07-27 11:25:27 BRT
LOG: checkpoint record is at 0/42C4B4
LOG: redo record is at 0/42C4B4; undo record is at 0/0; shutdown TRUE
LOG: next transaction ID: 0/593; next OID: 10820
LOG: next MultiXactId: 1; next MultiXactOffset: 0
LOG: database system is ready
FATAL: database "foo" does not exist
*/

Now, am I doing something terribly wrong/noobish, or Postgres is freaking
out because I want to create a database that does not exist?

It's freaking out because you are not the postgres user it expects
when trying to connect with createdb. It expects you to be the
postgres user, not the foo user. Your best move would be to wipe this
and reinstall using your OS's packages.

Cheers,
David.
--
David Fetter <david@fetter.org> http://fetter.org/
phone: +1 415 235 3778 AIM: dfetter666
Skype: davidfetter

Remember to vote!
Consider donating to PostgreSQL: http://www.postgresql.org/about/donate

#3Merlin Moncure
mmoncure@gmail.com
In reply to: David Fetter (#2)
Re: How do I create a database if I can't connect to it?

On 7/27/07, David Fetter <david@fetter.org> wrote:

On Fri, Jul 27, 2007 at 11:28:58AM -0300, Paolo Victor wrote:

Hello,

For a short description, I'll just show the sequence of commands I'm trying
to execute:

paolo@box> initdb -D /usr/local/pgsql/data/

This looks like a mistake. Unless you plan to develop the PostgreSQL
code itself, you should not be installing from source. Instead, you
should be using one from the packaging system your operating system
uses.

I don't necessarily agree with this advice. I encourage everyone who
is considering serious development with PostgreSQL to become familiar
with the database architecture...there are advantages to compiling
from source yourself if you know what you are doing, and simply
learning how to do it is a good exercise.

I am also very suspicious of the assertion that knowledge of how to
manually invoke initdb is not necessary. While the binary vs source
argument certainly debatable, I would certainly advise every
PostgreSQL dba to memorize the initdb man page for various reasons.
However, there are few reasons to run postgres directly, we normally
rely on pg_ctl for that (but it's still useful to know it can be
done).

anyways, to the OP, you need to connect to one of the default
databases (postgres, or template1) and create one from there...or
invoke the createdb command.

merlin

#4Paolo Victor
paolovictor@gmail.com
In reply to: Merlin Moncure (#3)
Re: How do I create a database if I can't connect to it?

First: Thanks for all the advice!

David:

I tried installing the system's packages, but as I plan using the python
procedures feature, I've got to compile it with the "--with-python" option.
I'm not sure if the default package already includes the feature, but since
the createlang command failed and I found out on some forum (sorry, I lost
the link) that I had to compile PG with this option set, I tried compiling
PG myself.

Oh, and I've already compiled PG before (but without the python option) and
had no problems. I'm trying to compile the 8.2.4 version, I'll try with
8.2.3.

Scott, Merlin:

When I try to connect to one of the default databases, here's what I get:

paolo@box:~$ psql -d template1 -p 5435
NOTICE: table "pg_class" was reindexed
NOTICE: table "sql_sizing" was reindexed
NOTICE: table "sql_sizing_profiles" was reindexed
NOTICE: table "sql_features" was reindexed
NOTICE: table "sql_implementation_info" was reindexed
NOTICE: table "sql_languages" was reindexed
NOTICE: table "sql_packages" was reindexed
NOTICE: table "sql_parts" was reindexed
NOTICE: table "pg_statistic" was reindexed
NOTICE: table "pg_type" was reindexed
NOTICE: table "pg_attribute" was reindexed
NOTICE: table "pg_proc" was reindexed
NOTICE: table "pg_autovacuum" was reindexed
NOTICE: table "pg_attrdef" was reindexed
NOTICE: table "pg_constraint" was reindexed
NOTICE: table "pg_inherits" was reindexed
NOTICE: table "pg_index" was reindexed
NOTICE: table "pg_operator" was reindexed
NOTICE: table "pg_opclass" was reindexed
NOTICE: table "pg_am" was reindexed
NOTICE: table "pg_amop" was reindexed
NOTICE: table "pg_amproc" was reindexed
NOTICE: table "pg_language" was reindexed
NOTICE: table "pg_largeobject" was reindexed
NOTICE: table "pg_aggregate" was reindexed
NOTICE: table "pg_rewrite" was reindexed
NOTICE: table "pg_trigger" was reindexed
NOTICE: table "pg_description" was reindexed
NOTICE: table "pg_cast" was reindexed
NOTICE: table "pg_namespace" was reindexed
NOTICE: table "pg_conversion" was reindexed
NOTICE: table "pg_depend" was reindexed
REINDEX

I get the same output when I execute the createuser command.

Show quoted text

On 7/27/07, Merlin Moncure <mmoncure@gmail.com> wrote:

On 7/27/07, David Fetter <david@fetter.org> wrote:

On Fri, Jul 27, 2007 at 11:28:58AM -0300, Paolo Victor wrote:

Hello,

For a short description, I'll just show the sequence of commands I'm

trying

to execute:

paolo@box> initdb -D /usr/local/pgsql/data/

This looks like a mistake. Unless you plan to develop the PostgreSQL
code itself, you should not be installing from source. Instead, you
should be using one from the packaging system your operating system
uses.

I don't necessarily agree with this advice. I encourage everyone who
is considering serious development with PostgreSQL to become familiar
with the database architecture...there are advantages to compiling
from source yourself if you know what you are doing, and simply
learning how to do it is a good exercise.

I am also very suspicious of the assertion that knowledge of how to
manually invoke initdb is not necessary. While the binary vs source
argument certainly debatable, I would certainly advise every
PostgreSQL dba to memorize the initdb man page for various reasons.
However, there are few reasons to run postgres directly, we normally
rely on pg_ctl for that (but it's still useful to know it can be
done).

anyways, to the OP, you need to connect to one of the default
databases (postgres, or template1) and create one from there...or
invoke the createdb command.

merlin

#5Paolo Victor
paolovictor@gmail.com
In reply to: Paolo Victor (#4)
Re: How do I create a database if I can't connect to it?

Ok, I found the problem: Permissions.

Although I -do- have write/read/exec permission /usr/local/pgsql , some
files couldn't be copied after the install, probably rendering PG a bit
unstable =)

I tried installing PG in a folder in my home directory, and it worked like a
charm.

Here's the output of the "sudo make install" command, when I tried
installing it at /usr/local/pgsql :

/*
Actually, for the sake of the internet's tubes, I'll just post the error
(and last) lines.

And for our non-portuguese-speaking friends:
Entrando no diretório = Entering Directory
Saindo do diretório = Leaving directory
*/

make[4]: Entrando no diretório `/home/paolo/Desktop/postgresql-8.2.4
/src/interfaces/ecpg/include'
cd ../../../.. && ./config.status src/interfaces/ecpg/include/ecpg_config.h
./config.status: line 91: conf20566.sh: Permission denied
./config.status: line 92: conf20566.sh: Permission denied
chmod: cannot access `conf20566.sh': No such file or directory
./config.status: line 206: conf20566.file: Permission denied
sed: couldn't close stdout: Permission denied
cat: write error: Permission denied
mkdir: cannot create directory `./confstat20566-20898': Permission denied
: cannot create a temporary directory in .
make[4]: ** [../../../../src/interfaces/ecpg/include/ecpg_config.h] Erro 1
make[4]: Saindo do diretório `/home/paolo/Desktop/postgresql-8.2.4
/src/interfaces/ecpg/include'
make[3]: ** [install] Erro 2
make[3]: Saindo do diretório `/home/paolo/Desktop/postgresql-8.2.4
/src/interfaces/ecpg'
make[2]: ** [install] Erro 2
make[2]: Saindo do diretório `/home/paolo/Desktop/postgresql-8.2.4
/src/interfaces'
make[1]: ** [install] Erro 2
make[1]: Saindo do diretório `/home/paolo/Desktop/postgresql-8.2.4/src'
make: ** [install] Erro 2

Show quoted text

On 7/27/07, Paolo Victor <paolovictor@gmail.com> wrote:

First: Thanks for all the advice!

David:

I tried installing the system's packages, but as I plan using the python
procedures feature, I've got to compile it with the "--with-python" option.
I'm not sure if the default package already includes the feature, but since
the createlang command failed and I found out on some forum (sorry, I lost
the link) that I had to compile PG with this option set, I tried compiling
PG myself.

Oh, and I've already compiled PG before (but without the python option)
and had no problems. I'm trying to compile the 8.2.4 version, I'll try
with 8.2.3.

Scott, Merlin:

When I try to connect to one of the default databases, here's what I get:

paolo@box:~$ psql -d template1 -p 5435
NOTICE: table "pg_class" was reindexed
NOTICE: table "sql_sizing" was reindexed
NOTICE: table "sql_sizing_profiles" was reindexed
NOTICE: table "sql_features" was reindexed
NOTICE: table "sql_implementation_info" was reindexed
NOTICE: table "sql_languages" was reindexed
NOTICE: table "sql_packages" was reindexed
NOTICE: table "sql_parts" was reindexed
NOTICE: table "pg_statistic" was reindexed
NOTICE: table "pg_type" was reindexed
NOTICE: table "pg_attribute" was reindexed
NOTICE: table "pg_proc" was reindexed
NOTICE: table "pg_autovacuum" was reindexed
NOTICE: table "pg_attrdef" was reindexed
NOTICE: table "pg_constraint" was reindexed
NOTICE: table "pg_inherits" was reindexed
NOTICE: table "pg_index" was reindexed
NOTICE: table "pg_operator" was reindexed
NOTICE: table "pg_opclass" was reindexed
NOTICE: table "pg_am" was reindexed
NOTICE: table "pg_amop" was reindexed
NOTICE: table "pg_amproc" was reindexed
NOTICE: table "pg_language" was reindexed
NOTICE: table "pg_largeobject" was reindexed
NOTICE: table "pg_aggregate" was reindexed
NOTICE: table "pg_rewrite" was reindexed
NOTICE: table "pg_trigger" was reindexed
NOTICE: table "pg_description" was reindexed
NOTICE: table "pg_cast" was reindexed
NOTICE: table "pg_namespace" was reindexed
NOTICE: table "pg_conversion" was reindexed
NOTICE: table "pg_depend" was reindexed
REINDEX

I get the same output when I execute the createuser command.

On 7/27/07, Merlin Moncure <mmoncure@gmail.com > wrote:

On 7/27/07, David Fetter <david@fetter.org > wrote:

On Fri, Jul 27, 2007 at 11:28:58AM -0300, Paolo Victor wrote:

Hello,

For a short description, I'll just show the sequence of commands I'm

trying

to execute:

paolo@box> initdb -D /usr/local/pgsql/data/

This looks like a mistake. Unless you plan to develop the PostgreSQL
code itself, you should not be installing from source. Instead, you
should be using one from the packaging system your operating system
uses.

I don't necessarily agree with this advice. I encourage everyone who
is considering serious development with PostgreSQL to become familiar
with the database architecture...there are advantages to compiling
from source yourself if you know what you are doing, and simply
learning how to do it is a good exercise.

I am also very suspicious of the assertion that knowledge of how to
manually invoke initdb is not necessary. While the binary vs source
argument certainly debatable, I would certainly advise every
PostgreSQL dba to memorize the initdb man page for various reasons.
However, there are few reasons to run postgres directly, we normally
rely on pg_ctl for that (but it's still useful to know it can be
done).

anyways, to the OP, you need to connect to one of the default
databases (postgres, or template1) and create one from there...or
invoke the createdb command.

merlin

#6Paolo Victor
paolovictor@gmail.com
In reply to: Paolo Victor (#5)
Re: How do I create a database if I can't connect to it?

On 7/27/07, Paolo Victor <paolovictor@gmail.com> wrote:

Ok, I found the problem: Permissions.

Although I -do- have write/read/exec permission /usr/local/pgsql , some
files couldn't be copied after the install, probably rendering PG a bit
unstable =)

Erm, I guess I mean "the config proccess failed" =)

I tried installing PG in a folder in my home directory, and it worked like a

Show quoted text

charm.

Here's the output of the "sudo make install" command, when I tried
installing it at /usr/local/pgsql :

/*
Actually, for the sake of the internet's tubes, I'll just post the error
(and last) lines.

And for our non-portuguese-speaking friends:
Entrando no diretório = Entering Directory
Saindo do diretório = Leaving directory
*/

make[4]: Entrando no diretório `/home/paolo/Desktop/postgresql- 8.2.4
/src/interfaces/ecpg/include'
cd ../../../.. && ./config.status
src/interfaces/ecpg/include/ecpg_config.h
./config.status: line 91: conf20566.sh: Permission denied
./config.status: line 92: conf20566.sh : Permission denied
chmod: cannot access `conf20566.sh': No such file or directory
./config.status: line 206: conf20566.file: Permission denied
sed: couldn't close stdout: Permission denied
cat: write error: Permission denied
mkdir: cannot create directory `./confstat20566-20898': Permission denied
: cannot create a temporary directory in .
make[4]: ** [../../../../src/interfaces/ecpg/include/ecpg_config.h] Erro 1
make[4]: Saindo do diretório `/home/paolo/Desktop/postgresql- 8.2.4
/src/interfaces/ecpg/include'
make[3]: ** [install] Erro 2
make[3]: Saindo do diretório `/home/paolo/Desktop/postgresql-8.2.4
/src/interfaces/ecpg'
make[2]: ** [install] Erro 2
make[2]: Saindo do diretório `/home/paolo/Desktop/postgresql- 8.2.4
/src/interfaces'
make[1]: ** [install] Erro 2
make[1]: Saindo do diretório `/home/paolo/Desktop/postgresql-8.2.4/src'
make: ** [install] Erro 2

On 7/27/07, Paolo Victor <paolovictor@gmail.com> wrote:

First: Thanks for all the advice!

David:

I tried installing the system's packages, but as I plan using the python
procedures feature, I've got to compile it with the "--with-python" option.
I'm not sure if the default package already includes the feature, but since
the createlang command failed and I found out on some forum (sorry, I lost
the link) that I had to compile PG with this option set, I tried compiling
PG myself.

Oh, and I've already compiled PG before (but without the python option)
and had no problems. I'm trying to compile the 8.2.4 version, I'll try
with 8.2.3.

Scott, Merlin:

When I try to connect to one of the default databases, here's what I
get:

paolo@box:~$ psql -d template1 -p 5435
NOTICE: table "pg_class" was reindexed
NOTICE: table "sql_sizing" was reindexed
NOTICE: table "sql_sizing_profiles" was reindexed
NOTICE: table "sql_features" was reindexed
NOTICE: table "sql_implementation_info" was reindexed
NOTICE: table "sql_languages" was reindexed
NOTICE: table "sql_packages" was reindexed
NOTICE: table "sql_parts" was reindexed
NOTICE: table "pg_statistic" was reindexed
NOTICE: table "pg_type" was reindexed
NOTICE: table "pg_attribute" was reindexed
NOTICE: table "pg_proc" was reindexed
NOTICE: table "pg_autovacuum" was reindexed
NOTICE: table "pg_attrdef" was reindexed
NOTICE: table "pg_constraint" was reindexed
NOTICE: table "pg_inherits" was reindexed
NOTICE: table "pg_index" was reindexed
NOTICE: table "pg_operator" was reindexed
NOTICE: table "pg_opclass" was reindexed
NOTICE: table "pg_am" was reindexed
NOTICE: table "pg_amop" was reindexed
NOTICE: table "pg_amproc" was reindexed
NOTICE: table "pg_language" was reindexed
NOTICE: table "pg_largeobject" was reindexed
NOTICE: table "pg_aggregate" was reindexed
NOTICE: table "pg_rewrite" was reindexed
NOTICE: table "pg_trigger" was reindexed
NOTICE: table "pg_description" was reindexed
NOTICE: table "pg_cast" was reindexed
NOTICE: table "pg_namespace" was reindexed
NOTICE: table "pg_conversion" was reindexed
NOTICE: table "pg_depend" was reindexed
REINDEX

I get the same output when I execute the createuser command.

On 7/27/07, Merlin Moncure <mmoncure@gmail.com > wrote:

On 7/27/07, David Fetter < david@fetter.org > wrote:

On Fri, Jul 27, 2007 at 11:28:58AM -0300, Paolo Victor wrote:

Hello,

For a short description, I'll just show the sequence of commands

I'm trying

to execute:

paolo@box> initdb -D /usr/local/pgsql/data/

This looks like a mistake. Unless you plan to develop the

PostgreSQL

code itself, you should not be installing from source. Instead, you

should be using one from the packaging system your operating system
uses.

I don't necessarily agree with this advice. I encourage everyone who
is considering serious development with PostgreSQL to become familiar
with the database architecture...there are advantages to compiling
from source yourself if you know what you are doing, and simply
learning how to do it is a good exercise.

I am also very suspicious of the assertion that knowledge of how to
manually invoke initdb is not necessary. While the binary vs source
argument certainly debatable, I would certainly advise every
PostgreSQL dba to memorize the initdb man page for various reasons.
However, there are few reasons to run postgres directly, we normally
rely on pg_ctl for that (but it's still useful to know it can be
done).

anyways, to the OP, you need to connect to one of the default
databases (postgres, or template1) and create one from there...or
invoke the createdb command.

merlin

#7Paolo Victor
paolovictor@gmail.com
In reply to: Paolo Victor (#6)
Re: How do I create a database if I can't connect to it?

Success!

Here's what happened:

1. I should -not- use sudo to "make install", since my user already had the
required permissions. Using sudo messed up and caused those permission
errors.
2. As I mentioned before, I did install pg through the package system
before. The problem is: when I removed the package, all of pg's bin files
(createdb, initdb, etc) remained at /usr/bin , conflicting with the new ones
at /usr/local/pgsql/bin. After removing the dupe files...

paolo@box:~$ postgres -D /home/paolo/db -p 5435 -i
LOG: database system was shut down at 2007-07-27 14:47:19 BRT
LOG: checkpoint record is at 0/42C424
LOG: redo record is at 0/42C424; undo record is at 0/0; shutdown TRUE
LOG: next transaction ID: 0/593; next OID: 10820
LOG: next MultiXactId: 1; next MultiXactOffset: 0
LOG: database system is ready

Terminal 2:
paolo@pira:~$ createdb nowItWorks -p 5435
CREATE DATABASE

:D

Once again thanks for the help and remember: Packaging systems may bite :o

Cheers,
Paolo

Show quoted text

On 7/27/07, Paolo Victor <paolovictor@gmail.com> wrote:

On 7/27/07, Paolo Victor <paolovictor@gmail.com> wrote:

Ok, I found the problem: Permissions.

Although I -do- have write/read/exec permission /usr/local/pgsql , some
files couldn't be copied after the install, probably rendering PG a bit
unstable =)

Erm, I guess I mean "the config proccess failed" =)

I tried installing PG in a folder in my home directory, and it worked like

a charm.

Here's the output of the "sudo make install" command, when I tried
installing it at /usr/local/pgsql :

/*
Actually, for the sake of the internet's tubes, I'll just post the
error (and last) lines.

And for our non-portuguese-speaking friends:
Entrando no diretório = Entering Directory
Saindo do diretório = Leaving directory
*/

make[4]: Entrando no diretório `/home/paolo/Desktop/postgresql- 8.2.4
/src/interfaces/ecpg/include'
cd ../../../.. && ./config.status
src/interfaces/ecpg/include/ecpg_config.h
./config.status: line 91: conf20566.sh: Permission denied
./config.status: line 92: conf20566.sh : Permission denied
chmod: cannot access `conf20566.sh': No such file or directory
./config.status: line 206: conf20566.file: Permission denied
sed: couldn't close stdout: Permission denied
cat: write error: Permission denied
mkdir: cannot create directory `./confstat20566-20898': Permission
denied
: cannot create a temporary directory in .
make[4]: ** [../../../../src/interfaces/ecpg/include/ecpg_config.h] Erro
1
make[4]: Saindo do diretório `/home/paolo/Desktop/postgresql- 8.2.4
/src/interfaces/ecpg/include'
make[3]: ** [install] Erro 2
make[3]: Saindo do diretório `/home/paolo/Desktop/postgresql-8.2.4
/src/interfaces/ecpg'
make[2]: ** [install] Erro 2
make[2]: Saindo do diretório `/home/paolo/Desktop/postgresql- 8.2.4
/src/interfaces'
make[1]: ** [install] Erro 2
make[1]: Saindo do diretório `/home/paolo/Desktop/postgresql-8.2.4/src'
make: ** [install] Erro 2

On 7/27/07, Paolo Victor <paolovictor@gmail.com> wrote:

First: Thanks for all the advice!

David:

I tried installing the system's packages, but as I plan using the
python procedures feature, I've got to compile it with the "--with-python"
option. I'm not sure if the default package already includes the feature,
but since the createlang command failed and I found out on some forum
(sorry, I lost the link) that I had to compile PG with this option set, I
tried compiling PG myself.

Oh, and I've already compiled PG before (but without the python
option) and had no problems. I'm trying to compile the 8.2.4 version,
I'll try with 8.2.3.

Scott, Merlin:

When I try to connect to one of the default databases, here's what I
get:

paolo@box:~$ psql -d template1 -p 5435
NOTICE: table "pg_class" was reindexed
NOTICE: table "sql_sizing" was reindexed
NOTICE: table "sql_sizing_profiles" was reindexed
NOTICE: table "sql_features" was reindexed
NOTICE: table "sql_implementation_info" was reindexed
NOTICE: table "sql_languages" was reindexed
NOTICE: table "sql_packages" was reindexed
NOTICE: table "sql_parts" was reindexed
NOTICE: table "pg_statistic" was reindexed
NOTICE: table "pg_type" was reindexed
NOTICE: table "pg_attribute" was reindexed
NOTICE: table "pg_proc" was reindexed
NOTICE: table "pg_autovacuum" was reindexed
NOTICE: table "pg_attrdef" was reindexed
NOTICE: table "pg_constraint" was reindexed
NOTICE: table "pg_inherits" was reindexed
NOTICE: table "pg_index" was reindexed
NOTICE: table "pg_operator" was reindexed
NOTICE: table "pg_opclass" was reindexed
NOTICE: table "pg_am" was reindexed
NOTICE: table "pg_amop" was reindexed
NOTICE: table "pg_amproc" was reindexed
NOTICE: table "pg_language" was reindexed
NOTICE: table "pg_largeobject" was reindexed
NOTICE: table "pg_aggregate" was reindexed
NOTICE: table "pg_rewrite" was reindexed
NOTICE: table "pg_trigger" was reindexed
NOTICE: table "pg_description" was reindexed
NOTICE: table "pg_cast" was reindexed
NOTICE: table "pg_namespace" was reindexed
NOTICE: table "pg_conversion" was reindexed
NOTICE: table "pg_depend" was reindexed
REINDEX

I get the same output when I execute the createuser command.

On 7/27/07, Merlin Moncure <mmoncure@gmail.com > wrote:

On 7/27/07, David Fetter < david@fetter.org > wrote:

On Fri, Jul 27, 2007 at 11:28:58AM -0300, Paolo Victor wrote:

Hello,

For a short description, I'll just show the sequence of commands

I'm trying

to execute:

paolo@box> initdb -D /usr/local/pgsql/data/

This looks like a mistake. Unless you plan to develop the

PostgreSQL

code itself, you should not be installing from source. Instead,

you

should be using one from the packaging system your operating

system

uses.

I don't necessarily agree with this advice. I encourage everyone
who
is considering serious development with PostgreSQL to become
familiar
with the database architecture...there are advantages to compiling
from source yourself if you know what you are doing, and simply
learning how to do it is a good exercise.

I am also very suspicious of the assertion that knowledge of how to
manually invoke initdb is not necessary. While the binary vs source
argument certainly debatable, I would certainly advise every
PostgreSQL dba to memorize the initdb man page for various reasons.
However, there are few reasons to run postgres directly, we normally

rely on pg_ctl for that (but it's still useful to know it can be
done).

anyways, to the OP, you need to connect to one of the default
databases (postgres, or template1) and create one from there...or
invoke the createdb command.

merlin

#8Tom Lane
tgl@sss.pgh.pa.us
In reply to: Merlin Moncure (#3)
Re: How do I create a database if I can't connect to it?

"Merlin Moncure" <mmoncure@gmail.com> writes:

On 7/27/07, David Fetter <david@fetter.org> wrote:

For a short description, I'll just show the sequence of commands I'm trying
to execute:

This looks like a mistake. Unless you plan to develop the PostgreSQL
code itself, you should not be installing from source.

I don't necessarily agree with this advice.

Me either. I was about to complain about this bit:

paolo@box> createdb foo -p 5435

which is in fact not valid switch syntax for createdb --- the dbname has
to come after optional switches --- and experimentation shows that every
createdb since about version 7.3 has rejected it. So either Paolo
wasn't giving us a verbatim transcript, or he had a really ancient
version of createdb in his path. Subsequent discussion suggests a
permissions issue but I'm not convinced that was all there was to it.
In any case "don't install from source" is bad/irrelevant advice.

regards, tom lane