How to restore a psql dump of version 9.6 into psql vesion 12(or greater) - psql

I've a psql dump of version 9.6.
I would like to restore it on Psql 12(or higher)

Related

AWS Elatic Beanstalk and rails: pg_restore: [archiver] unsupported version (1.13) in file header

I am trying to shift from heroku to amazon aws and after I dumped the db using:
heroku pg:backups:capture
heroku pg:backups:download
I ran:
eb ssh
cd /var/app/current
pg_restore -v -h $NAME.$ID.$DATACENTER.rds.amazonaws.com -U $RDS_ROOT_USER -d $DATABASE_NAME latest.dump
I get the following error:
pg_restore: [archiver] unsupported version (1.13) in file header
BTW I am using rails.
What am I doing wrong?
You're using an old version of pg_restore binary that doesn't support restoring the provided dump file. Please make sure that you use the latest Postgres version, which must be higher than the following release: https://www.postgresql.org/about/news/1834/ (10.3, 9.6.8, 9.5.12, 9.4.17, and 9.3.22).
You can check the pg_restore version you're using by running pg_restore --version.
If you are using a third-party tool, such as PgAdmin, to restore the provided dump file, the restore may not succeed even with the installed Postgres version being up to date. This is due to third-party tools often bundling their own versions of the pg_restore binary, that may not be up to date.
Follow this link: Why am I getting pg_restore

Migrate PostgreSQL database back to local machine

I've recently re-installed Mac OS X on my Macbook, and am just getting my development environment and projects back up and running again. For one of my Ruby on Rails apps (which is running on Heroku) I need to grab the (PostgreSQL) database from Heroku and migrate it back to my development environment. How would I go about doing this?
I fixed this by first creating my database (psql in Terminal) and then using the CREATE DATABASE db_name command. Then I used heroku pg:backups capture to capture a backup/shot of the database. I downloaded this using heroku pg:backups public-url b001 and then pg_restore --dbname=db_name --verbose /path/to/download.
Hope that hopes anyone!

CLI isn't recognizing psql command

I've installed the Windows version of Postgres, as explained in the instructions here, and when I try to call heroku pg:psql, I get an error saying The local psql command could not be located. I've tried installing Postgres inside my app directory, but that hasn't worked.
Have you tried this suggested solutions?
The local psql command could not be located
The problem was a difference between the version of postgres on heroku compared to the local version. Try running heroku pg:info and compare it to postgres --version

Rails 4 JSON attribute type not working with Postgres

I forked a repo from someone I'm collaborating with, and I'm just trying to get my development environment up and running. One of the migrations has a json attribute and we're using Postgres for both dev and production:
class CreateExams < ActiveRecord::Migration
def change
create_table :exams do |t|
t.belongs_to :user
t.json :exam
t.timestamps
end
end
end
database.yml
development:
adapter: postgresql
database: examgen_development
host: localhost
When I run the rake db:migrate, I get an error that would lead me to believe that PG doesn't support JSON column types:
PG::Error: ERROR: type "json" does not exist
But I know Postgres 9.2 supports JSON (i.e. http://www.postgresql.org/docs/devel/static/datatype-json.html).
Interestingly, when I check the version of PG I'm using with 'psql' it shows 9.0.4. Whereas when I use 'postgres' it shows 9.2.1. So I'm not exactly sure what version I'm using and how to go about switching back and forth.
psql --version
psql (PostgreSQL) 9.0.4
postgres --version
postgres (PostgreSQL) 9.2.1
Does anyone have thoughts as to why I'm getting that Postgres error?
OK, so it turns out at one point I had installed postgres via homebrew, and had also done so with Postgres.app at a different time. I began to realize this by checking the version of 'psql' and 'postgres' and noticed the distinction.
psql --version
psql (PostgreSQL) 9.0.4
postgres --version
postgres (PostgreSQL) 9.2.4
I uninstalled Postgres.app using their documentation here and then using homebrew ensured I was using the most recent version of postgres.

Error creating Rails DB using rake db:create

I'm attempting to get my first "hello world" rails example going using the rails' getting started guide on my OSX 10.6.3 box.
When I go to execute the first rake db:create command (I'm using mysql) I get:
simon#/Users/simon/source/rails/blog/config: rake db:create (in /Users/simon/source/rails/blog) Couldn't create database for {"reconnect"=>false, "encoding"=>"utf8", "username"=>"root", "adapter"=>"mysql", "database"=>"blog_development", "pool"=>5, "password"=>nil, "socket"=>"/opt/local/var/run/mysql5/mysqld.sock"}, charset: utf8, collation: utf8_unicode_ci (if you set the charset manually, make sure you have a matching collation)
I found plenty of stackoverflow questions addressing this problem with the following advice:
Verify that user and password are correct (I'm running w/ no password for root on my dev box)
Verify that the socket is correct - I can cat the socket, so I assume it's correct
Verify that the user can create a DB (As you can see root can connect and create a this DB no problem)
simon#/Users/simon/source/rails/blog/config: mysql -uroot -hlocalhost
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 5.1.45 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database blog_development;
Query OK, 1 row affected (0.00 sec)
to ensure that this wasn't a charset issue I also tried:
mysql> create database foobar CHARACTER SET utf8 COLLATE utf8_general_ci;
Query OK, 1 row affected (0.00 sec)
Note: here is my database.yaml:
development:
adapter: mysql
encoding: utf8
reconnect: false
database: blog_development
pool: 5
username: root
password:
socket: /opt/local/var/run/mysql5/mysqld.sock
# host: localhost
Note that I tried switching socket to localhost with no effect.
Any idea on what might be going on here?
Thanks for all the help guys. Looks like the problem had to do with my install of the mysql gem under OSX.
#tim after I proceeded to the next step and got up and going I got an error on the console, so I did a bit of searching and found this helpful thread.
After I uninstalled my ruby gems gem uninstall mysql I installed the proper mysql gems using this command (from the thread):
export ARCHFLAGS="-arch i386 -arch x86_64" ; gem install --no-rdoc --no-ri mysql -- --with-mysql-dir=/opt/local/lib/mysql5 --with-mysql-config=/opt/local/lib/mysql5/bin/mysql_config
After executing this one I was able to successfully run rake db:create and proceed.
Thanks!!
It could be a number of things.
Is your database set for utf8 character set?
Is the path to the socket correct, since it varies from OS.
Have you reinstalled the mysql gem? sudo gem install mysql
It might be MySQL, you might want to downgrade the version to 5.0
Other than that, I'm not sure.
You should post here your database.yml
To make your test better, i would try to create a database UTF-8 to see if your database supports utf-8
create database foobar CHARACTER SET utf8 COLLATE utf8_general_ci
Does the blog_development database already exist?
If so, you can just continue to the next step.
Try running ruby script/server in the blog/ directory.
If it doesn't error out, then you should be able to navigate to localhost:3000 and continue the tutorial from here http://guides.rubyonrails.org/getting_started.html#hello-rails.
Leave me a comment if ruby script/server errors out.
I just had the same issue : it was an old mysql gem which was not up to date. Re-installing the mysql gem did the trick.
Re-install mysql-server and mysql-client using this command:
sudo apt-get install mysql-server mysql-client
and then some libraries you need to install to make MySQL available to ruby:
sudo apt-get install libmysql-ruby
This all solved my problem. Try it !!! :)

Resources