PostgreSQL 2019(1)Install PostgreSQL 10.9 on Ubuntu

阅读更多
PostgreSQL 2019(1)Install PostgreSQL 10.9 on Ubuntu

Currently, the latest version is https://www.postgresql.org/ftp/source/v11.4/

> wget https://ftp.postgresql.org/pub/source/v11.4/postgresql-11.4.tar.gz
> tar zxvf postgresql-11.4.tar.gz

It seems I need version 10 to support my software.
https://www.postgresql.org/ftp/source/v10.9/
> wget https://ftp.postgresql.org/pub/source/v10.9/postgresql-10.9.tar.gz
> tar zxvf postgresql-10.9.tar.gz

> ./configure --prefix=/home/carl/tool/postgresql-10.9
> make
> make install

Install the tools
> cd contrib/
> make
> make install

Add to the Path
> sudo ln -s /home/carl/tool/postgresql-10.9 /opt/postgresql-10.9
> sudo ln -s /opt/postgresql-10.9 /opt/postgresql

export PATH="/opt/postgresql/bin:$PATH"

Check installation and version
> postgres --version
postgres (PostgreSQL) 10.9

Init the database
> initdb -D /opt/postgresql/data/

Start the database service
> pg_ctl -D /opt/postgresql/data/ -l logfile start

List the database we have
> psql -l
                              List of databases
   Name    | Owner | Encoding |   Collate   |    Ctype    | Access privileges
-----------+-------+----------+-------------+-------------+-------------------
postgres  | carl  | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
template0 | carl  | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/carl          +
           |       |          |             |             | carl=CTc/carl
template1 | carl  | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/carl          +
           |       |          |             |             | carl=CTc/carl

Create a database, owner carl, database name demo
> createdb -Ocarl -Eutf-8 demo

Connect to the database
> psql -U carl -d demo -h localhost

List all database after that
> \l
                              List of databases
   Name    | Owner | Encoding |   Collate   |    Ctype    | Access privileges
-----------+-------+----------+-------------+-------------+-------------------
demo      | carl  | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
postgres  | carl  | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
template0 | carl  | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/carl          +
           |       |          |             |             | carl=CTc/carl
template1 | carl  | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/carl          +
           |       |          |             |             | carl=CTc/carl

Create table
> demo=# create table usertable(name VARCHAR(20), signupdate DATE);
CREATE TABLE

Insert data
> insert into usertable (name, signupdate ) values ('sillycat', '2019-07-23' );
INSERT 0 1

Select data
> select * from usertable;
   name   | signupdate
----------+------------
sillycat | 2019-07-23

List all the tables
> \d
         List of relations
Schema |   Name    | Type  | Owner
--------+-----------+-------+-------
public | usertable | table | carl

List the connection
> \conninfo
You are connected to database "demo" as user "carl" on host "localhost" at port "5432".

Password
> export PGPASSWORD=test
> psql -U carl -d demo -h ubuntu-master -p 5432




References:
https://www.postgresql.org/ftp/source/



你可能感兴趣的:(PostgreSQL 2019(1)Install PostgreSQL 10.9 on Ubuntu)