Psql: Difference between revisions

From annawiki
Line 83: Line 83:
  You already discovered this scheme in the previous section using createdb.
  You already discovered this scheme in the previous section using createdb.
No. I did not.
No. I did not.
===II. PostgreSQL Client Applications===
http://www.postgresql.org/docs/9.3/static/reference-client.html
This part contains reference information for PostgreSQL client applications
and utilities. Not all of these commands are of general utility;
These commands? The first sentence did not contain the word "command".

Revision as of 2013-11-21T13:10:54

Connection

tobiasco@main:/root$ psql
psql: FATAL:  database "tobiasco" does not exist

Who asked or claimed that?

tobiasco@main:/root$ psql postgres
psql (9.3.1)
Type "help" for help.

postgres=>
postgres=> \c tidb_all
You are now connected to database "tidb_all" as user "tobiasco".
tidb_all=>
tidb_all=>

Create database

tobiasco@main:/root$ psql CREATE DATABASE test2;
psql: warning: extra command-line argument "test2" ignored
psql: FATAL:  Peer authentication failed for user "DATABASE"

Try without test2

tobiasco@main:/root$ psql CREATE DATABASE;
psql: FATAL:  Peer authentication failed for user "DATABASE"

Create table

tobiasco@main:/root$ psql test
psql (9.3.1)
Type "help" for help.
 
test=> CREATE TABLE testtable
test-> \dt test
No matching relations found.
test->

Try with semicolon:

test=> CREATE TABLE testtable;
ERROR:  syntax error at or near ";"
LINE 1: CREATE TABLE testtable;

Create DB and CREATEDB

test-> \dg
                             List of roles
 Role name |                   Attributes                   | Member of
-----------+------------------------------------------------+-----------
 gis       |                                                | {}
 postgres  | Superuser, Create role, Create DB, Replication | {}
 tobiasco  | Create DB                                      | {}

But http://www.postgresql.org/docs/9.3/static/sql-createdatabase.html says

"To create a database, you must be a superuser or have the special CREATEDB privilege."

Where to find out what "privilege" one has?

There are different kinds of privileges: SELECT, INSERT, UPDATE, 
DELETE, TRUNCATE, REFERENCES, TRIGGER, CREATE, CONNECT, TEMPORARY, EXECUTE, and USAGE.

No "Create DB" nor "CREATEDB", but it is not claimed that this list is complete.

For complete information on the different types of privileges 
supported by PostgreSQL, refer to the GRANT reference page.

Refer to? It would be nice to have a complete list of all "different types of privileges supported by PostgreSQL". Anyway, look at http://www.postgresql.org/docs/9.3/static/sql-grant.html

createdb -- create a new PostgreSQL database
[...]
createdb creates a new PostgreSQL database.
[...]
createdb is a wrapper around the SQL command CREATE DATABASE.

So, that is not the privilege "CREATEDB" here, but a wrapper? No interest in wrapper.

Documentation

There are at least two parts labeled with a Roman number I:

I. Tutorial

Those who set up and manage their own server should also read Part III.

Does one need to read "I" to find out that one needs to read "III" to manage an own server? If not, then isn't it superfluous is? And yes, it is in the http://www.postgresql.org/docs/9.3/static/preface.html - redundancy bloats the documentation.

1.4. Accessing a Database

You already discovered this scheme in the previous section using createdb.

No. I did not.


II. PostgreSQL Client Applications

http://www.postgresql.org/docs/9.3/static/reference-client.html

This part contains reference information for PostgreSQL client applications 
and utilities. Not all of these commands are of general utility;

These commands? The first sentence did not contain the word "command".