Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
PostgreSQL Administration Essentials

You're reading from   PostgreSQL Administration Essentials Discover efficient ways to administer, monitor, replicate, and handle your PostgreSQL databases

Arrow left icon
Product type Paperback
Published in Oct 2014
Publisher Packt
ISBN-13 9781783988983
Length 142 pages
Edition 1st Edition
Languages
Arrow right icon
Toc

Understanding the existing databases

Once the database has been launched, we can connect to PostgreSQL using a psql frontend:

psql postgres

Ideally, you connect to a database called postgres, which can be found in any database instance. Some systems don't encourage people to log in as a postgres user. Therefore, you might want to use sudo here as well to log in to PostgreSQL. If this works for you, you can make PostgreSQL display a list of existing databases, where \l will do the job:

postgres=# \x
Expanded display is on.
postgres=# \l
List of databases
-[ RECORD 1 ]-----+----------------------
Name              | postgres
Owner             | postgres
Encoding          | UTF8
Collate           | en_US.UTF-8
Ctype             | en_US.UTF-8
Access privileges |
-[ RECORD 2 ]-----+----------------------
Name              | template0
Owner             | postgres
Encoding          | UTF8
Collate           | en_US.UTF-8
Ctype             | en_US.UTF-8
Access privileges | =c/postgres
                  | postgres=CTc/postgres
-[ RECORD 3 ]-----+----------------------
Name              | template1
Owner             | postgres
Encoding          | UTF8
Collate           | en_US.UTF-8
Ctype             | en_US.UTF-8
Access privileges | =c/postgres
                  | postgres=CTc/postgres

Congratulations, you've completed your first task using the psql shell. If you executed \l as proposed, you might have seen that the table is too wide to be displayed properly. To avoid this, you can use \x to transpose the output and display each column as a separate line. This little feature can come in handy whenever you have to read a wide table.

Tip

If you want to customize the psql shell for your needs, you might want to consider writing a .psqlrc file. It can automatically set things such as \x for you on every login.

In an empty database instance, you will already find the three existing databases template0, template1, and postgres. The rule for you as an end user is simple: always connect to the postgres database and try to avoid connections to the template databases (template0 does not allow connections anyway); these databases are only here to act as a role model in case you create a new database. Make sure that no useless objects are in template0 or template1 because whenever you create an additional database, these useless objects are cloned.

You have been reading a chapter from
PostgreSQL Administration Essentials
Published in: Oct 2014
Publisher: Packt
ISBN-13: 9781783988983
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime