2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

psqlコマンドのインストール

Last updated at Posted at 2016-11-13

Amazon Linux 1 (Cloud9)

2020-10-11時点でのインストール手順です。

(参考) https://www.postgresql.org/download/linux/redhat/

PostgreSQL公式RPMパッケージのダウンロード

コマンド
wget https://download.postgresql.org/pub/repos/yum/reporpms/EL-6-x86_64/pgdg-redhat-repo-latest.noarch.rpm
結果(例)
--2020-10-11 00:47:02--  https://download.postgresql.org/pub/repos/yum/reporpms/EL-6-x86_64/pgdg-redhat-repo-latest.noarch.rpm
Resolving download.postgresql.org (download.postgresql.org)... 72.32.157.246, 147.75.85.69, 87.238.57.227, ...
Connecting to download.postgresql.org (download.postgresql.org)|72.32.157.246|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 6636 (6.5K) [application/x-redhat-package-manager]
Saving to: ‘pgdg-redhat-repo-latest.noarch.rpm’

pgdg-redhat-repo-latest.noarch.rpm     100%[===========================================================================>]   6.48K  --.-KB/s    in 0s      

2020-10-11 00:47:03 (244 MB/s) - ‘pgdg-redhat-repo-latest.noarch.rpm’ saved [6636/6636]

PostgreSQL公式RPMパッケージのインストール

コマンド
sudo rpm -Uvh --nodeps pgdg-redhat-repo-latest.noarch.rpm
結果(例)
warning: pgdg-redhat-repo-latest.noarch.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:pgdg-redhat-repo-42.0-11         ################################# [100%]

リポジトリ設定ファイルの修正

コマンド
sudo sed --in-place -e "s/\$releasever/6/g" /etc/yum.repos.d/pgdg-redhat-all.repo
結果(例)
(出力なし)

PostgreSQLクライアントのインストール

コマンド
sudo yum install -y postgresql12
結果(例)
Loaded plugins: priorities, update-motd, upgrade-helper
amzn-main                                                                                                                           | 2.1 kB  00:00:00     
amzn-updates                                                                                                                        | 3.8 kB  00:00:00     
epel/x86_64/metalink                                                                                                                | 7.8 kB  00:00:00     
epel                                                                                                                                | 4.7 kB  00:00:00     
pgdg-common                                                                                                                         | 2.9 kB  00:00:00     
pgdg10                                                                                                                              | 3.7 kB  00:00:00     
pgdg11                                                                                                                              | 3.6 kB  00:00:00     
pgdg12                                                                                                                              | 3.6 kB  00:00:00     
pgdg95                                                                                                                              | 3.7 kB  00:00:00     
pgdg96                                                                                                                              | 3.7 kB  00:00:00     
(1/11): pgdg11/x86_64/group_gz                                                                                                      |  245 B  00:00:00     
(2/11): pgdg12/x86_64/group_gz                                                                                                      |  245 B  00:00:00     
(3/11): pgdg-common/x86_64/primary_db                                                                                               |  81 kB  00:00:00     
(4/11): pgdg10/x86_64/group_gz                                                                                                      |  245 B  00:00:01     
(5/11): pgdg95/x86_64/group_gz                                                                                                      |  249 B  00:00:00     
(6/11): pgdg96/x86_64/group_gz                                                                                                      |  249 B  00:00:00     
(7/11): pgdg12/x86_64/primary_db                                                                                                    | 142 kB  00:00:00     
(8/11): pgdg10/x86_64/primary_db                                                                                                    | 174 kB  00:00:01     
(9/11): pgdg11/x86_64/primary_db                                                                                                    | 168 kB  00:00:01     
(10/11): pgdg96/x86_64/primary_db                                                                                                   | 185 kB  00:00:00     
(11/11): pgdg95/x86_64/primary_db                                                                                                   | 172 kB  00:00:01     
1225 packages excluded due to repository priority protections
Resolving Dependencies
--> Running transaction check
---> Package postgresql12.x86_64 0:12.4-1PGDG.rhel6 will be installed
--> Processing Dependency: postgresql12-libs(x86-64) = 12.4-1PGDG.rhel6 for package: postgresql12-12.4-1PGDG.rhel6.x86_64
--> Processing Dependency: libpq.so.5()(64bit) for package: postgresql12-12.4-1PGDG.rhel6.x86_64
--> Running transaction check
---> Package postgresql12-libs.x86_64 0:12.4-1PGDG.rhel6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================================================================
 Package                                   Arch                           Version                                     Repository                      Size
===========================================================================================================================================================
Installing:
 postgresql12                              x86_64                         12.4-1PGDG.rhel6                            pgdg12                         1.7 M
Installing for dependencies:
 postgresql12-libs                         x86_64                         12.4-1PGDG.rhel6                            pgdg12                         339 k

Transaction Summary
===========================================================================================================================================================
Install  1 Package (+1 Dependent package)

Total download size: 2.0 M
Installed size: 9.6 M
Downloading packages:
warning: /var/cache/yum/x86_64/latest/pgdg12/packages/postgresql12-libs-12.4-1PGDG.rhel6.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEYA 
Public key for postgresql12-libs-12.4-1PGDG.rhel6.x86_64.rpm is not installed
(1/2): postgresql12-libs-12.4-1PGDG.rhel6.x86_64.rpm                                                                                | 339 kB  00:00:02     
(2/2): postgresql12-12.4-1PGDG.rhel6.x86_64.rpm                                                                                     | 1.7 MB  00:00:02     
-----------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                      787 kB/s | 2.0 MB  00:00:02     
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG
Importing GPG key 0x442DF0F8:
 Userid     : "PostgreSQL RPM Building Project <pgsqlrpms-hackers@pgfoundry.org>"
 Fingerprint: 68c9 e2b9 1a37 d136 fe74 d176 1f16 d2e1 442d f0f8
 Package    : pgdg-redhat-repo-42.0-11.noarch (installed)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
** Found 1 pre-existing rpmdb problem(s), 'yum check' output follows:
pgdg-redhat-repo-42.0-11.noarch has missing requires of /etc/redhat-release
  Installing : postgresql12-libs-12.4-1PGDG.rhel6.x86_64                                                                                               1/2 
  Installing : postgresql12-12.4-1PGDG.rhel6.x86_64                                                                                                    2/2 
  Verifying  : postgresql12-12.4-1PGDG.rhel6.x86_64                                                                                                    1/2 
  Verifying  : postgresql12-libs-12.4-1PGDG.rhel6.x86_64                                                                                               2/2 

Installed:
  postgresql12.x86_64 0:12.4-1PGDG.rhel6                                                                                                                   

Dependency Installed:
  postgresql12-libs.x86_64 0:12.4-1PGDG.rhel6                                                                                                              

Complete!

確認

コマンド
which psql
結果(例)
/usr/bin/psql

MacPorts

コマンド
sudo /opt/local/bin/port install postgresql96
sudo /opt/local/bin/port select postgresql postgresql96
/opt/local/bin/port select postgresql
結果(例)
Available versions for postgresql:
	none
	postgresql96 (active)
コマンド
which psql
結果(例)
/opt/local/bin/psql

HomeBrew

コマンド
sudo brew install postgresql

Amazon Linux (Yum)

コマンド
sudo yum install postgresql96.x86_64 -y
コマンド
which psql
結果(例)
/opt/bin/psql
2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?