Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
3 views17 pages

Tutorial 01 - PostgreSQL Environment

Uploaded by

mou3taz91
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views17 pages

Tutorial 01 - PostgreSQL Environment

Uploaded by

mou3taz91
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Tutorial 01: SQL DDL commands

PostgreSQL is a powerful, open source object-relational database system that uses and
extends the SQL language combined with many features that safely store and scale the
most complicated data workloads. The origins of PostgreSQL date back to 1986 as part
of the POSTGRES project at the University of California at Berkeley and has more than
30 years of active development on the core platform.
Download the installer certified by EnterpriseDB for all supported PostgreSQL
versions.

This installer includes the PostgreSQL server, pgAdmin; a graphical tool for managing
and developing your databases, and StackBuilder; a package manager that can be used
to download and install additional PostgreSQL tools and drivers. Stackbuilder includes
management, integration, migration, replication, geospatial, connectors and other tools.

This installer can run in graphical or silent install modes. The installer is designed to be
a straightforward, fast way to get up and running with PostgreSQL on Windows.

Advanced users can also download a zip archive of the binaries, without the installer.
This download is intended for users who wish to include PostgreSQL as part of another
application installer.

To download postgres installer for windows open postgresql website [


https://www.postgresql.org/ ].

Click on the Download button to open the download page:

Mohammed Mahmoud
1
In postgres download page click on windows to open windows installer download page.

In the windows download click on Download installer.

Mohammed Mahmoud
2
In download windows installer page, specify the desired version of PostgreSQL and
specify windows type and then click on the download now button.

Install PostgreSQL:
Double click on the installer file, an installation wizard will appear and guide you
through multiple steps where you can choose different options that you would like to
have in PostgreSQL.

One of the common error in installer is Unable to Write inside environment variable
path.

Mohammed Mahmoud
3
1. Open the regedit, and go to HKEY_LOCAL_MACHINE\Software\Microsoft\Windows
Script Host\Settings.
2. In the right panel, you will see Enabled. If you see the entry 0, it means that the
Windows Script Host access is disabled on your Windows machine. Double Click
on it and give it Value Data 1 to enable it. A value of 1 will enable Windows Script
Host A value of 0 will disable Windows Script Host.
3. For windows 10 navigate to: HKEY_CURRENT_USER\Software\Microsoft\Windows
Script Host\Settings.
4. Then double-click on PostgreSQL installer to start the installation process. The
installer will install Microsoft Visual C++ Redistributable before starting install
PostgreSQL.

Wait until Microsoft Visual C++ Redistributable complete. Sometimes you get a
problem in Microsoft Visual C++ Redistributable. Therefore, you can install the
PostgreSQL through the command Prompt.

Mohammed Mahmoud
4
1. From start menu open accessories and then right click on Command Prompt and
then select Run as Administrator.
2. And use the command cd to open the PostgreSQL setup folder and then type the
following command: [ postgresql-10.5-1-windows-x64.exe --install_runtimes 0].

Mohammed Mahmoud
5
The first window in installation process. Welcome to the PostgreSQL setup wizard.

Mohammed Mahmoud
6
Specify installation folder, choose your own or keep the default folder suggested by
PostgreSQL installer. And then click Next.

Mohammed Mahmoud
7
Determine the required features. And then click Next.

Specify Data folder, choose your own or keep the default folder suggested by
PostgreSQL installer. And then click Next.

Mohammed Mahmoud
8
Enter the password for the database superuser (postgres) and service account. And then
click Next.

Mohammed Mahmoud
9
Enter the port for PostgreSQL. Make sure that no other applications are using this port.
Leave it as default if you are unsure. And then click Next.

Choose the default locale used by the database. And then click Next.

Mohammed Mahmoud
10
Review the installation settings. And then click Next.

Mohammed Mahmoud
11
If you are ready to start the installation process. Click Next.

Wain until the installation process complete.

Mohammed Mahmoud
12
Now the PostgreSQL installation has completed. At the end of installation process, the
PostgreSQL installer gives you an option to open Stack Builder to download and install
additional tools to complement your PostgreSQL installation. It require to be connected
to internet.

Mohammed Mahmoud
13
From stack builder select PostgreSQL server and then click next to see the available
tools.

You can select the required additional tools from the tools list. Then click Next to
complete the installation. Now we do not need to install any tools. Therefore, Click
cancel. Then Yes.

SQL Shell (psql):


SQL Shell (psql) is the interactive terminal for working with Postgres. Theres an
abundance of flags available for use when working with psql.
To start SQL Shell (psql), from start menu Open PostgreSQL and then select SQL Shell
(psql).

Mohammed Mahmoud
14
In SQL Shell Terminal use the default server [localhost], default database [postgres],
default port [5432] and default username [postgres], and then enter the password of
postgres user which specified during the installation process.

SQL Shell (psql) Common commands:


1. To show all database use the following command:

postgres=# \l
List of databases

Name | Owner | Encoding | Collate | Ctype | Access privileges

--------------+----------+----------+----------------------------+----------------------------+-----------------------

Mohammed Mahmoud
15
geodatabase | postgres | UTF8 | English_United States.1252 | English_United States.1252 |

geonode | geonode | UTF8 | English_United States.1252 | English_United States.1252 |

geonode_data | geonode | UTF8 | English_United States.1252 | English_United States.1252 |

mydatabase | postgres | UTF8 | English_United States.1252 | English_United States.1252 |

postgres | postgres | UTF8 | English_United States.1252 | English_United States.1252 |

template0 | postgres | UTF8 | English_United States.1252 | English_United States.1252 | =c/postgres +

| | | | | postgres=CTc/postgres

template1 | postgres | UTF8 | English_United States.1252 | English_United States.1252 | =c/postgres +

| | | | | postgres=CTc/postgres

(7 rows)

-- More --

2. To show a list of schema use the following command:

postgres=# \dn

List of schemas
Name | Owner
--------+----------
public | postgres
(1 row)

3. To show the list of tables in the database use the following command.

postgres=# \d

List of relations
Schema | Name | Type | Owner
--------+-----------+-------+----------
public | employees | table | postgres
(1 row)

4. To show additional information about database tables use the following commands:

postgres=# \d+

List of relations
Schema | Name | Type | Owner | Size | Description
--------+-----------+-------+----------+------------+-------------
public | employees | table | postgres | 8192 bytes |
(1 row)

5. To show table description (table structure) use the following command:

Mohammed Mahmoud
16
postgres=# \d employees;

Table "public.employees"
Column | Type | Collation | Nullable | Default
--------+-----------------------+-----------+----------+---------
id | integer | | |
ename | character varying(50) | | |
salary | double precision | | |

6. To show description of table with additional information use the following


command:

postgres=# \d+ employees;

Table "public.employees"

Column | Type | Collation | Nullable | Default | Storage | Stats target | Description

--------+-----------------------+-----------+----------+---------+----------+--------------+-------------

id | integer | | | | plain | |

ename | character varying(50) | | | | extended | |

salary | double precision | | | | plain | |

7. To show all function in the database use the following command:

postgres=# \df

List of functions
Schema | Name | Result data type | Argument data types | Type
--------+------+------------------+---------------------+------
(0 rows)

8. To connect to another database use \c or \connect command as following:

postgres=# \c geonode;

WARNING: Console code page (850) differs from Windows code page (1252)
8-bit characters might not work correctly. See psql reference
page "Notes for Windows users" for details.
You are now connected to database "geonode" as user "postgres".

To open your default text editor inside SQL Shell use the following command:

postgres=# \e

9. To quite from SQL Shell use the following command:

postgres=# \q

Mohammed Mahmoud
17

You might also like