在 AWS Amazon Linux (EC2) AMI 上安装 PostgreSQL Client v10
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/49573258/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Installing PostgreSQL Client v10 on AWS Amazon Linux (EC2) AMI
提问by Ismar Slomic
I have successfully launched new AWS RDS PostgreSQL v10instance and need to install PostgreSQL v10 client on Amazon Linux EC2 instance.
我已经成功启动了新的 AWS RDS PostgreSQL v10实例,需要在 Amazon Linux EC2 实例上安装 PostgreSQL v10 客户端。
I have tried to install it with yum
, but it cant find the package for v10:
我试图用 安装它yum
,但它找不到 v10 的包:
[ec2-user@ip-X-X-X-X ~]$ sudo yum install -y postgresql10
Loaded plugins: priorities, update-motd, upgrade-helper
amzn-main | 2.1 kB 00:00:00
amzn-updates | 2.5 kB 00:00:00
No package postgresql110 available.
Error: Nothing to do
Previously I managed to install PostgreSQL client v9.5 with:
以前我设法安装了 PostgreSQL 客户端 v9.5:
[ec2-user@ip-X-X-X-X ~]$ sudo yum install -y postgresql95
I guess I need to add Postgres yum repository, as mentioned in https://www.postgresql.org/download/linux/redhat/. But what Platform should I choose for Amazon Linux? Red Hat?
我想我需要添加 Postgres yum 存储库,如https://www.postgresql.org/download/linux/redhat/ 中所述。但是我应该为 Amazon Linux 选择什么平台?红帽?
回答by Haneef Mohammed
Packages/Repos which is designed to work of RedHat will work on Amazon Linux also, Amazon Linux is a minimal-install version of RHEL. You may run into compatibility issues if you select old version of Amazon Linux (Amazon linux 1) for the below steps, otherwise it should work fine in the latest version Amazon Linux 2.
专为 RedHat 设计的 Packages/Repos 也适用于 Amazon Linux,Amazon Linux 是 RHEL 的最小安装版本。如果您为以下步骤选择旧版本的 Amazon Linux (Amazon linux 1),您可能会遇到兼容性问题,否则它应该可以在最新版本的 Amazon Linux 2 中正常工作。
Check Amazon Linux version
检查亚马逊 Linux 版本
[ec2-user ~]$ cat /etc/system-release
Amazon Linux release 2.0 (2017.12) LTS Release Candidate
Install RHEL 7 yum repo for PostgreSQL
为 PostgreSQL 安装 RHEL 7 yum repo
[ec2-user ~]$ sudo yum install -y https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-redhat10-10-2.noarch.rpm
[ec2-user ~]$ sudo sed -i "s/rhel-$releasever-$basearch/rhel-latest-x86_64/g" "/etc/yum.repos.d/pgdg-10-redhat.repo"
Install PostgreSQL Client v10
安装 PostgreSQL 客户端 v10
[ec2-user ~]$ sudo yum install -y postgresql10
[ec2-user ~]$ psql --version
psql (PostgreSQL) 10.3
Read more about Amazon Linux 2
阅读有关Amazon Linux 2 的更多信息
Note! Amazon Linux 2 provides additional package installation through Amazon Linux Extras Repository(amazon-linux-extras
) ((client only)). Since postgresql10 is not yet available, adding extra yum repo is the only solution per today.
笔记!Amazon Linux 2 通过Amazon Linux Extras Repository( amazon-linux-extras
)((仅限客户端))提供额外的软件包安装。由于 postgresql10 尚不可用,添加额外的 yum 存储库是目前唯一的解决方案。
UDATE 2019May
UDATE 2019五月
those who see
看到的人
Error: Package: pgdg-redhat-repo-42.0-4.noarch (/pgdg-redhat-repo-latest.noarch)
Requires: /etc/redhat-release
错误:包:pgdg-redhat-repo-42.0-4.noarch (/pgdg-redhat-repo-latest.noarch)
需要:/etc/redhat-release
may still install step by step all dependencies and the server with:
仍然可以逐步安装所有依赖项和服务器:
yum install -y https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-latest-x86_64/postgresql10-libs-10.7-2PGDG.rhel7.x86_64.rpm
yum install -y https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-latest-x86_64/postgresql10-10.7-2PGDG.rhel7.x86_64.rpm
yum install -y https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-latest-x86_64/postgresql10-server-10.7-2PGDG.rhel7.x86_64.rpm
回答by johnthuss
sudo amazon-linux-extras install postgresql10
须藤 amazon-linux-extras 安装 postgresql10
回答by arudzinska
Since none of the previous answers worked for me, I'm adding a solution that let me install the postgresql10 client. We're using VERSION="2018.03"
of Amazon Linux AMI in our pipelines.
由于之前的答案都不适用于我,我添加了一个让我安装 postgresql10 客户端的解决方案。我们VERSION="2018.03"
在我们的管道中使用Amazon Linux AMI。
Building from source:
从源头构建:
Note: The link below points to postgresql 10.4, you may want to check for newer subversions
注意:下面的链接指向 postgresql 10.4,您可能需要检查更新的 subversions
sudo yum install -y gcc readline-devel zlib-devel
wget https://ftp.postgresql.org/pub/source/v10.4/postgresql-10.4.tar.gz
tar -xf postgresql-10.4.tar.gz
cd postgresql-10.4
./configure
make -C src/bin
sudo make -C src/bin install
make -C src/include
sudo make -C src/include install
make -C src/interfaces
sudo make -C src/interfaces install
make -C doc
sudo make -C doc install
The new package should be installed with all its executables in here: /usr/local/pgsql/bin
新软件包应与其所有可执行文件一起安装在此处: /usr/local/pgsql/bin
Now, keep in mind that commands psql
, pg_dump
etc. still point to the old version of the psql client. You can run with the full executable paths (/usr/local/pgsql/bin/psql
) or prepend the new directory at the beginning of your $PATH
so that the system will look it up first:
现在,请记住,命令psql
,pg_dump
等仍指向旧版本psql客户端可以的。您可以使用完整的可执行路径 ( /usr/local/pgsql/bin/psql
) 运行或在开头添加新目录,$PATH
以便系统首先查找它:
Edit ~/.bash_profile
adding this at the end:
编辑~/.bash_profile
在最后添加这个:
export PATH="/usr/local/pgsql/bin:$PATH"
Then run:
然后运行:
source ~/.bash_profile
Now everything should be ready:
现在一切都应该准备好了:
[ec2-user@ip-xx-x-x-xxx ~]$ psql --version
psql (PostgreSQL) 10.4
回答by steamer25
Adapting Haneef Mohammed's answer for Amazon Linux 1 (tested on 2018.03):
改编 Haneef Mohammed 对 Amazon Linux 1 的回答(在 2018.03 上测试):
Go to the Postgres repositories pageand grab the URL for 'Red Hat Enterprise Linux 6 - x86_64'. Install the PG repos and amend the entries, replacing '$releasever' with '6.9' (or newer?):
转到 Postgres存储库页面并获取“Red Hat Enterprise Linux 6 - x86_64”的 URL。安装 PG 存储库并修改条目,将 '$releasever' 替换为 '6.9'(或更新的?):
[ec2-user ~]$ sudo yum install -y https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-6-x86_64/pgdg-redhat10-10-2.noarch.rpm
[ec2-user ~]$ sudo sed -i "s/rhel-$releasever-$basearch/rhel-6.9-x86_64/g" "/etc/yum.repos.d/pgdg-10-redhat.repo"
Second part is the same:
第二部分是一样的:
[ec2-user ~]$ sudo yum install -y postgresql10
[ec2-user ~]$ psql --version
psql (PostgreSQL) 10.3
回答by jmwicks
As of May 25th, 2019, the following direct RPM installation worked for me on Amazon Linux 1 2018.03 (latest Beanstalk platform version) to install PostgreSQL Client 10.7:
截至 2019 年 5 月 25 日,以下直接 RPM 安装对我在 Amazon Linux 1 2018.03(最新 Beanstalk 平台版本)上安装 PostgreSQL Client 10.7 有效:
sudo rpm -ivh --force https://yum.postgresql.org/testing/10/redhat/rhel-6-x86_64/postgresql10-libs-10.7-2PGDG.rhel6.x86_64.rpm
sudo rpm -ivh --force https://yum.postgresql.org/testing/10/redhat/rhel-6-x86_64/postgresql10-10.7-2PGDG.rhel6.x86_64.rpm
回答by Chetan kapoor
PGDG repo is no longer available for Amazon Linux. So you can use amazon repo.
PGDG 存储库不再适用于 Amazon Linux。所以你可以使用亚马逊回购。
amazon-linux-extras install postgresql10 vim epel -y
Or follow this article
或者关注这篇文章
https://installvirtual.com/install-postgresql-10-on-amazon-ec2/
https://installvirtual.com/install-postgresql-10-on-amazon-ec2/
回答by Ryan Weaver
The way I resolved the issue was by running
我解决问题的方法是运行
yum clean all
before
前
yum install -y postgresql10
on Amazon Linux
在亚马逊 Linux 上
回答by iqbal125
This my 2019 solution:
这是我 2019 年的解决方案:
Just do
做就是了
sudo amazon-linux-extras install postgresql9.6
You should not have to download it from any outside source, since it is already given to you by default from Amazon, all you have to do is install it.
您不必从任何外部来源下载它,因为默认情况下它已经从亚马逊提供给您,您所要做的就是安装它。
The other solutions didnt work for me and I spent a good amount time banging my head against the wall trying to figure out why.
其他解决方案对我不起作用,我花了很多时间用头撞墙试图找出原因。
And surprisingly even though you install psql9.6 you get version 10.
令人惊讶的是,即使您安装了 psql9.6,您也会得到版本 10。
回答by user459911
for v11 on Amazon Linux 2 I had to do
对于 Amazon Linux 2 上的 v11,我必须这样做
yum -y install https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm
sed -i "s/rhel-$releasever-$basearch/rhel-7-x86_64/g" "/etc/yum.repos.d/pgdg-11-centos.repo"
回答by ANU MOHAN
PSql10.7 installation (08/20/2019)
PSql10.7 安装 (08/20/2019)
Remove all of the older version Psql client and perform the below steps:
删除所有旧版本的 Psql 客户端并执行以下步骤:
wget https://yum.postgresql.org/10/redhat/rhel-6.9-x86_64/postgresql10-libs-10.7-1PGDG.rhel6.x86_64.rpm
wget https://yum.postgresql.org/10/redhat/rhel-6.9-x86_64/postgresql10-10.7-1PGDG.rhel6.x86_64.rpm
sudo rpm -ivh postgresql10-libs-10.7-1PGDG.rhel6.x86_64.rpm
sudo rpm -ivh postgresql10-10.7-1PGDG.rhel6.x86_64.rpm