데이터를 잃지 않고 PostgreSQL을 버전 9.6에서 버전 10.1로 업그레이드하는 방법은 무엇입니까?
Ruby on Rails 애플리케이션 (Mac OS X 10.9)에 PostgreSQL 데이터베이스를 사용하고 있습니다.PostgreSQL 데이터베이스를 업그레이드하는 방법에 대한 자세한 지침이 있습니까?데이터베이스의 데이터를 파괴하거나 엉망으로 만들 것 같습니다.
자가 추출을 사용하여 Postgres를 설치 및 업그레이드했다고 가정하면 다음 단계를 수행 할 수 있습니다.
- 현재 Postgres 서버를 중지하십시오.
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
- 새 10.1 데이터베이스를 초기화하십시오.
initdb /usr/local/var/postgres10.1 -E utf8
- 실행
:pg_upgrade
(참고 : 아래 이외의 버전에서 업그레이드하는 경우 bin 버전 변경)pg_upgrade -v \ -d /usr/local/var/postgres \ -D /usr/local/var/postgres10.1 \ -b /usr/local/Cellar/postgresql/9.6.5/bin/ \ -B /usr/local/Cellar/postgresql/10.1/bin/
자세한 내부 로깅을 활성화하려면-v
이전 데이터베이스 클러스터 구성 디렉토리-d
새로운 데이터베이스 클러스터 구성 디렉토리-D
이전 PostgreSQL 실행 파일 디렉토리-b
새로운 PostgreSQL 실행 파일 디렉토리-B
- 새 데이터를 제자리로 이동 :
cd /usr/local/var mv postgres postgres9.6 mv postgres10.1 postgres
- Postgres를 다시 시작하십시오.
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
-
세부 사항을 점검 하고 새 서버가 올바르게 시작되었는지 확인하십시오./usr/local/var/postgres/server.log
- 마지막으로 레일
젬을 다시 설치하십시오.pg
gem uninstall pg gem install pg
좌절을 최소화하기 위해 위의 단계에서 수행하는 작업을 정확하게 이해하기 위해
를 읽는 데 시간이 걸릴 것을 제안합니다 .
우분투
사용자를 위한 솔루션은 다음과 같습니다.먼저 postgresql을 중지해야합니다
sudo /etc/init.d/postgresql stop
/etc/apt/sources.list.d/pgdg.list라는 새 파일을 만들고 아래 행을 추가하십시오
deb http://apt.postgresql.org/pub/repos/apt/ utopic-pgdg main
아래 명령을 따르십시오
wget -q -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install postgresql-9.4
sudo pg_dropcluster --stop 9.4 main
sudo /etc/init.d/postgresql start
이제 우리는 모든 것을 가지고 있습니다. 아래와 같이 업그레이드해야합니다.
sudo pg_upgradecluster 9.3 main
sudo pg_dropcluster 9.3 main
그게 다야. 대부분 업그레이드 된 클러스터는 포트 번호 5433에서 실행됩니다. 아래 명령으로 확인하십시오.
sudo pg_lsclusters
위의 모든 대답에도 불구하고 여기 5 센트가갑니다.모든 OS 및 모든 postgres 버전에서 작동합니다.
- 실행중인 postgres 인스턴스를 중지하십시오.
- 새 버전을 설치하고 시작하십시오. 새 버전에도 연결할 수 있는지 확인하십시오.
- 이전 버전의 변경
postgresql.conf
->port
에서5432
에5433
; - 이전 버전의 postgres 인스턴스를 시작하십시오.
- 터미널과
cd
새 버전bin
폴더 를 엽니 다 . - 운영
pg_dumpall -p 5433 -U <username> | psql -p 5432 -U <username>
- 이전 postgres 실행 인스턴스를 중지하십시오.
깊이에서이 주제를 다룹니다. 당신은 할 수 있습니다 :
-
그 자리에서; 또는pg_upgrade
-
그리고pg_dump
.pg_restore
확실하지 않은 경우 덤프로 처리하십시오. 오래된 데이터 디렉토리를 삭제하지 마십시오. 문제가 생길 경우를 대비하여 실수하십시오 / 실수합니다. 그렇게하면 변경되지 않은 9.3 설치로 돌아갈 수 있습니다.자세한 내용은 설명서를 참조하십시오.갇혀 있다면 어떻게 갇혀 있는지, 어디서, 무엇을 먼저 시도했는지 설명하는 자세한 질문을 게시하십시오. (다행히도) OS X 용 PostgreSQL의 여러 "분배"가 있기 때문에 PostgreSQL 설치 방법에 따라 다릅니다. 따라서 해당 정보를 제공해야합니다.
업데이트
:이 프로세스는 9.6에서 10으로 업그레이드 할 때와 동일합니다. 단순히 버전을 반영하도록 명령을 수정
9.6
하고
10
어디
9.6
는 IS
이전
버전과
10
는 IS
새로운
버전. "old"및 "new"디렉토리도 적절히 조정하십시오.
방금 Ubuntu에서 PostgreSQL 9.5를 9.6으로 업그레이드했으며 인식해야 할 OS / 패키지 관련 뉘앙스가 몇 가지 있으므로 결과를 공유한다고 생각했습니다.(
데이터를 수동으로 덤프하고 복원하고 싶지 않았으므로
여기에있는 다른 답변 중 일부는 실행 가능하지 않았습니다.)요컨대, 프로세스는 이전 버전 (예 : 9.5 및 9.6)과 함께 새 버전의 PostgreSQL을 설치 한 다음 https://www.postgresql.org/의
pg_upgrade
일부에 설명 된 바이너리 를 실행하는 과정으로 구성됩니다.
docs / 9.6 / static / pgupgrade.html
.유일한 "까다로운"측면은
pg_upgrade
인수에 대한 올바른 값을 전달하지 않거나
cd
명령을 실행하기 전에 올바른 사용자 또는 올바른 위치에 로그인하지 못하면 암호 오류 메시지가 발생할 수 있다는 것입니다."공식"저장소를 사용하고
deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main
있고 기본 파일 시스템 경로 또는 런타임 옵션을 변경하지 않은 경우 우분투 (및 아마도 데비안) 에서 다음 절차를 수행해야합니다.새 버전을 설치하십시오 (
9.6
명시 적으로을 지정 함 ).
sudo apt install postgresql-9.6
설치가 성공하면 두 버전이 나란히 실행되지만 다른 포트에서 실행됩니다. 설치 결과는 아래에 언급되어 있지만 간과하기 쉽습니다.
Creating new cluster 9.6/main ...
config /etc/postgresql/9.6/main
data /var/lib/postgresql/9.6/main
locale en_US.UTF-8
socket /var/run/postgresql
port 5433
두 서버 인스턴스를 모두 중지하십시오 (동시에 둘 다 중지됨).
sudo systemctl stop postgresql
전용 PostgreSQL 시스템 사용자로 전환하십시오.
su postgres
그의 홈 디렉토리로 이동하십시오 (실패하면 오류가 발생 함).
cd ~
pg_upgrade
다음 입력이 필요 합니다 (
pg_upgrade --help
이것을 알려줍니다).
When you run pg_upgrade, you must provide the following information:
the data directory for the old cluster (-d DATADIR)
the data directory for the new cluster (-D DATADIR)
the "bin" directory for the old version (-b BINDIR)
the "bin" directory for the new version (-B BINDIR)
이러한 입력은 "긴 이름"으로 지정되어보다 쉽게 시각화 할 수 있습니다.
-b, --old-bindir=BINDIR old cluster executable directory
-B, --new-bindir=BINDIR new cluster executable directory
-d, --old-datadir=DATADIR old cluster data directory
-D, --new-datadir=DATADIR new cluster data directory
We must also pass the --new-options
switch, because failure to do so results in the following:
connection to database failed: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/lib/postgresql/.s.PGSQL.50432"?
This occurs because the default configuration options are applied in the absence of this switch, which results in incorrect connection options being used, hence the socket error.
Execute the pg_upgrade
command from the new PostgreSQL version:
/usr/lib/postgresql/9.6/bin/pg_upgrade --old-bindir=/usr/lib/postgresql/9.5/bin --new-bindir=/usr/lib/postgresql/9.6/bin --old-datadir=/var/lib/postgresql/9.5/main --new-datadir=/var/lib/postgresql/9.6/main --old-options=-cconfig_file=/etc/postgresql/9.5/main/postgresql.conf --new-options=-cconfig_file=/etc/postgresql/9.6/main/postgresql.conf
Logout of the dedicated system user account:
exit
The upgrade is now complete, but, the new instance will bind to port 5433
(the standard default is 5432
), so keep this in mind if attempting to test the new instance before "cutting-over" to it.
Start the server as normal (again, this will start both the old and new instances):
systemctl start postgresql
If you want to make the new version the default, you will need to edit the effective configuration file, e.g., /etc/postgresql/9.6/main/postgresql.conf
, and ensure that the port is defined as such:
port = 5432
If you do this, either change the old version's port number to 5433
at the same time (before starting the services), or, simply remove the old version (this will not remove your actual database content; you would need to use apt --purge remove postgresql-9.5
for that to happen):
apt remove postgresql-9.5
The above command will stop all instances, so you'll need to start the new instance one last time with:
systemctl start postgresql
As a final point of note, don't forget to consider pg_upgrade
's good advice:
Upgrade Complete
----------------
Optimizer statistics are not transferred by pg_upgrade so,
once you start the new server, consider running:
./analyze_new_cluster.sh
Running this script will delete the old cluster's data files:
./delete_old_cluster.sh
If you are using homebrew and homebrew services, you can probably just do:
brew services stop postgresql
brew upgrade postgresql
brew postgresql-upgrade-database
brew services start postgresql
I think this might not work completely if you are using advanced postgres features, but it worked perfectly for me.
Standing on the shoulders of the other poor creatures trodding through this muck, I was able to follow these steps to get back up and running after an upgrade to Yosemite:
Assuming you've used home-brew to install and upgrade Postgres, you can perform the following steps.
-
Stop current Postgres server:
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
-
Initialize a new 9.4 database:
initdb /usr/local/var/postgres9.4 -E utf8
-
Install postgres 9.3 (as it was no longer present on my machine):
brew install homebrew/versions/postgresql93
-
Add directories removed during Yosemite upgrade:
mkdir -p /usr/local/var/postgres/{pg_tblspc,pg_twophase,pg_stat_tmp}/touch /usr/local/var/postgres/{pg_tblspc,pg_twophase,pg_stat_tmp}/.keep
-
run
pg_upgrade
:pg_upgrade -v -d /usr/local/var/postgres -D /usr/local/var/postgres9.4 -b /usr/local/Cellar/postgresql93/9.3.5/bin/ -B /usr/local/Cellar/postgresql/9.4.0/bin/
-
Move new data into place:
cd /usr/local/var mv postgres postgres9.3 mv postgres9.4 postgres
-
Restart Postgres:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
-
Check
/usr/local/var/postgres/server.log
for details and to make sure the new server started properly. -
Finally, re-install related libraries?
pip install --upgrade psycopg2 gem uninstall pg gem install pg
Looks like the solution has been baked into Homebrew now:
$ brew info postgresql
...
==> Caveats
To migrate existing data from a previous major version of PostgreSQL run:
brew postgresql-upgrade-database
....
This did it for me.
https://gist.github.com/dideler/60c9ce184198666e5ab4
Short and to the point. I honestly don't aim to understand the guts of PostgreSQL, I want to get stuff done.
On Windows I kept facing different errors messages when trying to use pg_upgrade
.
Saved a lot of time for me to just:
- Backup DB
- Uninstall all copies of PostgreSQL
- Install 9.5
- Restore DB
My solution was to do a combination of these two resources:
https://gist.github.com/tamoyal/2ea1fcdf99c819b4e07d
and
http://www.gab.lc/articles/migration_postgresql_9-3_to_9-4
The second one helped more then the first one. Also to not, don't follow the steps as is as some are not necessary. Also, if you are not being able to backup the data via postgres console, you can use alternative approach, and backup it with pgAdmin 3 or some other program, like I did in my case.
Also, the link: https://help.ubuntu.com/stable/serverguide/postgresql.html Helped to set the encrypted password and set md5 for authenticating the postgres user.
After all is done, to check the postgres server
version run in terminal:
sudo -u postgres psql postgres
After entering the password run in postgres terminal:
SHOW SERVER_VERSION;
It will output something like:
server_version
----------------
9.4.5
For setting and starting postgres I have used command:
> sudo bash # root
> su postgres # postgres
> /etc/init.d/postgresql start
> /etc/init.d/postgresql stop
And then for restoring database from a file:
> psql -f /home/ubuntu_username/Backup_93.sql postgres
Or if doesn't work try with this one:
> pg_restore --verbose --clean --no-acl --no-owner -h localhost -U postgres -d name_of_database ~/your_file.dump
And if you are using Rails do a bundle exec rake db:migrate
after pulling the code :)
I think this is best link for your solution to update postgres to 9.6
https://sandymadaan.wordpress.com/2017/02/21/upgrade-postgresql9-3-9-6-in-ubuntu-retaining-the-databases/
For Mac via homebrew:
brew tap petere/postgresql
,
brew install <formula>
(eg: brew install petere/postgresql/postgresql-9.6
)
Remove old Postgres:
brew unlink postgresql
brew link -f postgresql-9.6
If any error happen, don't forget to read and follow brew instruction in each step.
Check this out for more: https://github.com/petere/homebrew-postgresql
On Windows 10 since I had npm, I installed rimraf package. npm install rimraf -g
Backup all your databases one by one using command pg_dump -U $username --format=c --file=$mydatabase.sqlc $dbname
Then Installed Latest PostgreSQL Version i.e. 11.2 which prompted me to use port 5433 this time.
Followed by Uninstall of older versions of PostgreSQL mine was 10. Note the uninstaller may give a warning of not deleting folder C:\PostgreSQL\10\data
. That's why we have the next step using rimraf to permanently delete the folder and it's sub-folders.
change into PostgreSQL install directory and ran the command rimraf 10
. 10 is a directory name. Note use your older version of PostgreSQL i.e. 9.5 or something.
Now add C:\PostgreSQL\pg11\bin, C:\PostgreSQL\pg11\lib
into the Windows environmental variables. Note my new installed version is 11 thus why I am using pg11
.
Navigate to C:\PostgreSQL\data\pg11
then open postgresql.conf
edit port = 5433
to port = 5432
That's it. Open cmd and type psql -U postgres
You can now restore all your backed databases one by one using the command pg_restore -U $username --dbname=$databasename $filename
'programing' 카테고리의 다른 글
string.IsNullOrEmpty (string) vs. string.IsNullOrWhiteSpace (string) (0) | 2020.05.10 |
---|---|
LESS를 사용하지 않고 부트 스트랩 탐색 모음 축소 중단 점 변경 (0) | 2020.05.10 |
부동 소수점을 소수점 2 자리로 서식 지정 (0) | 2020.05.10 |
jquery 비활성화 양식 제출시 (0) | 2020.05.10 |
Internet Explorer에서 MVC4 DataType.Date EditorFor가 Chrome에 날짜 값을 표시하지 않음 (0) | 2020.05.09 |