Note: Install PostgreSQL 9.5 on Ubuntu 18.04

Since you can't mess with the production environment, there are times when you want to prepare a specific version of the DB environment in another environment. It is a memo for myself in such a case.

postgreSQL 9.5 installation

curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list
apt update
apt install postgresql-9.5

start postgreSQL

systemctl start [email protected]

Login

su postgres
psql -U

Database list display

# \l
                                   List of databases
    Name     |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges
-------------+----------+----------+-------------+-------------+-----------------------
 postgres    | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 template0   | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
             |          |          |             |             | postgres=CTc/postgres
 template1   | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
             |          |          |             |             | postgres=CTc/postgres

Database creation

create database test

Create table

Set the pkey column as the primary key.

 create table test (pkey serial primary key, id integer);

Table list display

# \d
              List of relations
 Schema |     Name      |   Type   |  Owner
--------+---------------+----------+----------
 public | test          | table    | postgres
 public | test_pkey_seq | sequence | postgres
(2 rows)

When postgreSQL sets the primary key, the "test_pkey_seq" table is automatically created.

Table selection

postgres=# \c test
You are now connected to database "test" as user "postgres".

Table setting display

# \d test
                          Table "public.test"
 Column |  Type   |                      Modifiers
--------+---------+-----------------------------------------------------
 pkey   | integer | not null default nextval('test_pkey_seq'::regclass)
 id     | integer |
Indexes:
    "test_pkey" PRIMARY KEY, btree (pkey)

Data insert

insert into test (id) values ('5'); 

Check the contents of the table

# select * from test;
 pkey | id
------+----
    1 |  5
(4 rows)

pkey is automatic.

Add column

# alter table test add column id2 integer;

I can't connect to postgreSQL from another console even though the command is correct.

psql -U postgres test
psql: FATAL:  Peer authentication failed for user "postgres"
cd /etc/postgresql/9.5/main
vim pg_hba.conf

pg_nba.Before changing conf


local   all             postgres                                peer

pg_nba.After changing conf


local   all             postgres                                md5  

Restart postgreSQL.

systemctrl restart postgresql

I was connected at another terminal. OK OK.


Recommended Posts

Note: Install PostgreSQL 9.5 on Ubuntu 18.04
Install pyqt5 on ubuntu
Install Ruby on Ubuntu 20.04
Install PostgreSQL 12 on Centos8
Install Realtek network driver on Ubuntu Note
Install Autoware on Ubuntu 18.04.5
Install Homebrew on Ubuntu 20.04
Install PostgreSQL 13 on CentOS 7.5
How to install NVIDIA driver on Ubuntu 18.04 (Note)
Install OpenJDK7 (JAVA) on ubuntu 14.04
Install Cybozu Office 10 on Ubuntu 20.4
Install zabbix agent (5.0) on Ubuntu 18.04
Install MAV Proxy on Ubuntu 18.04
Install Arudino IDE on Ubuntu 20
Install Java on WSL Ubuntu 18.04
Install Ubuntu Desktop 20.10 on RaspberryPi4
Install Arduino IDE on Ubuntu 20.04
Install raspi-config on Ubuntu 20.04 (LTS)
Install WordPress 5.5 on Ubuntu 20.04 LTS
Install PlantUML on Intellij on Ubuntu
Install Ubuntu Server 20.04 on Btrfs
Install AWS IoT Greengrass on Ubuntu
Install JDK and JRE on Ubuntu 16.10
Install ngrok on ubuntu16.04 using Vagrant
Note Book: OpenBLAS Install On Windows10
How to install WildFly on Ubuntu 18.04
Install MQTT broker Mosquitto on Ubuntu 18.04
Install SonarQube on ECS instance on Ubuntu 16.04
Note Book: LAPACK Install On Windows 10
Note Book: VTK Install On Windows10
Install ruby on Ubuntu 20.04 with rbenv
Install imagick on macOS Catalina + php 7.4 Note
Headless install of Ubuntu 20.10 on Raspberry Pi
Install OpenJDK (Java) on the latest Ubuntu
How to install production Metabase on Ubuntu
I want to install PHP 7.2 on Ubuntu 20.04.
tmux on Ubuntu
Wine settings on Ubuntu 18.04 (install WOLF RPG Editor)
Build and install Wireshark Development Release (3.3.1) on Ubuntu
Install Ubuntu Core 18 on Raspberry Pi 2 Model B
How to install network drivers on standalone Ubuntu
Note Book: OpenCV with CUDA Install On Windows10
How to install multiple JDKs on Ubuntu 18.04 LTS
Install and switch between multiple Javas on Ubuntu
Screen recording on Ubuntu 20.04
Web Bluetooth on Ubuntu20.04
Install gradle on mac
Install Corretto 8 on Windows
Install OpenJDK on macOS
Try DisplayLink on Ubuntu 20.04
Reinstall Kubernetes on Ubuntu 19.10
Install Java on Mac
Install Golang on CentOS 8
Install Neo4j 4.1.3 on centOS
Note: Ubuntu installation location
Run PostgreSQL on Java
Install Docker on Manjaro
Install Vertica 10.0 on CentOS 6.10
Install Gradle with ubuntu16.04
Install lombok on SpringToolSuite4
Install Python 3 on CentOS 7