如何在Ubuntu 18.04上更改Postgres版本

huangapple go评论68阅读模式
英文:

How to Change Postgres Version using ubuntu 18.04

问题

我在我的Ubuntu 18.04版本中安装了多个版本的PostgreSQL,我的扩展保存在PostgreSQL版本12中,但当我运行以下命令时:

sudo -u postgres psql

进入Postgres并通过输入以下命令来创建扩展:

create extension addme;

它显示错误,说在版本10中未创建扩展(addme.control和addme--0.0.1.sql),但它在版本12中存在。

如何在Ubuntu 18.04上更改Postgres版本

有人可以告诉我如何访问版本12,以便我可以访问这些扩展。

谢谢。

英文:

I have multiple versions of PostgreSQL installed in my ubuntu version 18.04 and my extensions are saved in Postgresql version 12 but when I run:

sudo -u postgres psql

command to enter Postgres and creating extensions by entering command

create extension addme;

It is showing me error of not created extension(addme.control and addme--0.0.1.sql) in version 10 but it is in version 12.

如何在Ubuntu 18.04上更改Postgres版本

Can anyone tell me how to access version 12 in which I can access those extensions.

Thank You.

答案1

得分: 2

只需尝试手动切换到版本(12),您需要按照以下步骤执行:

  1. 停止当前的 PostgreSQL 服务器(默认为 10)。
  2. 找出所需版本的 PostgreSQL 安装位置。
  3. 手动启动服务器:
/usr/local/pgsql-12/bin/pg_ctl -D /usr/local/pgsql-12/data start
  1. 现在您可以连接到该版本的数据库,并可以看到您创建的扩展,您还可以通过设置 PG_Version 到 PostgreSQL12 路径来使用导出作为替代方法。
英文:

so simply just try to go to the version(12) manually you need to perform the following in order

  1. stop the current server of the PostgreSQL (default 10)
  2. find out where the desired version of PostgreSQL is installed
  3. start the server manually
/usr/local/pgsql-12/bin/pg_ctl -D /usr/local/pgsql-12/data start
  1. now you are able to connect to the database using that version and you can see the extension you created besides you can use export as an alternative way by setting up the PG_Version to the PostgreSQL12 path.

答案2

得分: 1

主要解决方案是停止不需要的版本服务器,并使用版本12重新开始。可以通过设置所需的路径变量并使用 sudo service postgresql start 启动PostgreSQL服务器,或者您可以 cd 到所需的PostgreSQL版本目录并运行服务器。

英文:

The primary solution is to stop the undesired version server and take a fresh start with the version 12. This can be done by either setting the desired path variable and starting the postgres server using sudo service postgresql start or you would cd to the desired postgres version directory and run the server.

答案3

得分: 1

我建议您使用Docker镜像来管理不同的版本,以便它们可以独立运行,或者使用PostgreSQL版本管理器

英文:

I would recommend you, use docker images for different versions so that they work independently or use the PostgreSQL version manager.

答案4

得分: 0

在处理多个版本时,我已经配置/安装了Postgres到特定版本的单独目录中。你的配置是什么样的?

英文:

When working with multiple versions, I have configured\installed Postgres in separate directory for particular version. How is your configuration look like?

答案5

得分: 0

要访问版本12,您需要在安装版本12的目录中工作。看起来您目前正在版本10的目录中工作。只需使用 pg_ctl stop -l log 关闭版本10服务器,并使用 cd {版本12目录的位置} 切换到版本12目录并在那里工作。

英文:

To access version 12, you will have to work in the directory where you have installed version 12. It seems like you are currently working on a version 10 directory. Simply shut the version 10 server off using pg_ctl stop -l log and redirect to the version 12 directory using cd {location of the version 12 directory} and work from there.

答案6

得分: 0

一个替代方案是使用PotsgreSQL版本管理器:PGVM

我认为它可以帮助您管理PG版本。

英文:

An alternative is to use PotsgreSQL versions manager: PGVM

I think that it can help you to manage the PG versions.

答案7

得分: 0

非常重要的是要注意,当使用不同版本的PostgreSQL时,您需要进入相应版本的PostgreSQL目录并手动启动服务器,手动启动的意思是像这样操作(假设我们要启动PostgreSQL-13):

cd /usr/local/pgsql-13/bin

然后执行:

./pg_ctl start -l logfile -D ./data

这将启动PostgreSQL-13并使用正确的依赖项(正确的数据集群)。还请注意,我故意在./pg_ctl中使用了./来指定我要执行当前目录(即PostgreSQL-13目录)中的pg_ctl文件。到目前为止,这应该可以解决您的问题,您应该能够无问题地创建扩展。

希望对您有所帮助,请告诉我进展如何!

英文:

It's very important to note that when having different postgres versions, you would have to cd to the postgres version directory and run the server manually, what I mean by manually is to do it like this (let's say we went to run postgres-13):

cd /usr/local/pgsql-13/bin

then

./pg_ctl start -l logfile -D ./data

this will run postgres-13 and use the correct dependencies for it (the correct data cluster), also note that I intentionally used ./ in ./pg_ctl to specify that I want to execute the pg_ctl file of the current directory which is the postgres-13 direcotry, this so far should solve the issue for you and you should be able to create extensions without issues.

I hope this helps and let me know how it goes with you!.

答案8

得分: 0

我建议您使用Docker,一切都将被隔离,您可能不会与不同版本的数据混淆。

这个教程 对于创建基础镜像非常有用,然后我在不同的容器中安装了不同版本的PostgreSQL,因此它们互不干扰。

英文:

I'd advise you to use docker, everything will be isolated and you probably won't get confused with data from different versions.

This tutorial was useful to create a base image, then I installed different versions of postgres in different containers, so they are not in contact with each other.

答案9

得分: 0

要逐个版本工作,您可以通过停止Postgres服务器并更新PATH变量到所需版本来在它们之间切换。

如果您是从源代码安装的,使用以下命令停止服务器:

pg_ctl -D path/to/database -l logfile stop

如果您是从软件包管理器安装的,使用以下命令:

sudo service postgresql stop

然后,将PATH变量设置为您的Postgres安装路径:

export PATH=/path/to/postgresql/bin:$PATH

使用以下命令重新启动服务器:

sudo service postgresql start

或者

pg_ctl -D path/to/database -l logfile start
英文:

To work with one version at a time, you can switch between them by stopping the Postgres server and updating the PATH variable to the desired version.

If you installed it from the source code, use the following command to stop the server:

pg_ctl -D path/to/database -l logfile stop

If you installed it from the package manager, use:

sudo service postgresql stop

Then, set the PATH variable to your Postgres installation:

export PATH=/path/to/postgresql/bin:$PATH

Start the server again with:

sudo service postgresql start

or

pg_ctl -D path/to/database -l logfile start

答案10

得分: 0

如果您有多个版本的PostgreSQL,请确保它们不都在同一个端口上运行。如果它们在同一端口上运行,您可以更改PostgreSQL配置文件中的端口,或者您可以首先停止当前的服务器使用以下命令:bin/pg_ctl -D 'your_active_database' stop,然后进入您想要使用的PostgreSQL源代码安装目录(假设它已经安装),运行以下命令:bin/pg_ctl -D 'your_database' -l logfile start,然后运行bin/psql --port=5430 'your_database'

英文:

If you have several versions of postgres, make sure they they are not all running on the same port, if they are, you can change the ports on the postgres configuration file, or you can first stop the current server using bin/pg_ctl -D 'your_active_database' stop, then go to the postgres source code installation you'd like to use (assuming it's already installed) and run bin/pg_ctl -D 'your_database' -l logfile start then bin/psql --port=5430 'your_database'.

答案11

得分: 0

我可以理解您要求的内容,以下是翻译好的部分:

"update-alternatives --config psql.1.gz" 可以轻松更改,只需使用少数命令,并选择您想要的版本。

英文:

I changed easliy with few commands:

update-alternatives --config psql.1.gz

and select version whatever you want.

答案12

得分: 0

如果您有多个版本的PostgreSQL,并且想要使用其中一个。一个解决方案是可以使用Docker分别安装每个版本,以确保它们不会相互干扰。但如果您不想使用Docker,只需前往特定PostgreSQL版本的目录,并使用以下命令在该目录中启动服务器。

sudo service postgresql start

如果服务器已经在运行,您可以将上述命令中的"start"替换为"stop"以停止服务器。

英文:

If you have multiple versions of postgres and you want to use one. One solution you can use docker for installation of each version separately, So that they don't interfere with each other. But if you don't want to use docker you can just simply goto the directory of specific postgres version and start server in that directory using this commmand.

sudo service postgresql start

If the server is already running you can replace start to stop in the command above to stop the server.

答案13

得分: 0

你应该在版本12目录下工作并运行服务器。如上所述,现在似乎你正在一个不希望的目录上工作。

英文:

You should work in the version 12 directory and run the server. As mentioned above it seems you are working on an undesired directory right now.

答案14

得分: 0

如果您安装了多个版本的PostgreSQL,请首先停止所有正在运行的PostgreSQL服务器,然后转到您想要运行的PostgreSQL版本的目录,并从那里启动服务器。
使用以下命令来停止当前服务器:

pg_ctl -D path/to/database -l logfile stop

然后使用命令cd导航到您想要的PostgreSQL版本,然后在那里启动服务器:

pg_ctl -D path/to/database -l logfile start

您还可以为不同的版本使用不同的端口。

英文:

If you have multiple versions of postgresql installed you should first stop any postgreSQL server you have running, then go to the directory of the postgreSQL version you want to run and start the server from there.
Use this command to stop your current server

pg_ctl -D path/to/database -l logfile stop

then use the command cd to navigate to your desired postgresql version then
start your server there using

pg_ctl -D path/to/database -l logfile start

You can also use different ports for different versions.

答案15

得分: 0

我建议的是更改PATH变量并将其指向您的Postgres 12安装目录。这样,当您调用psql命令时,它将从您的Postgres安装中运行,其中已安装了扩展。

  1. 在终端中键入 sudo nano ~/.profile
  2. 将实际路径添加到PostgreSQL安装 export PATH=$PATH:/path/to/postgres/bin 到文件中。
  3. 然后键入 source ~/.profile 以应用更改。
英文:

What I would suggest is to change the PATH variable and point it to your Postgres 12 installation. That way when you call the psql command it will run from your postgres installation which has the extensions installed in it.

  1. Type sudo nano ~/.profile in the terminal.
  2. Add your actual path to the postgreSQL installation export PATH=$PATH:/path/to/postgres/bin to the file.
  3. Then type source ~/.profile to apply the changes.

huangapple
  • 本文由 发表于 2023年7月17日 22:35:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/76705533.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定