I'm writing a rails project using postgres and there is some data in the server. And I want dump the data from the remote end to the local, so I write script to do it, but some errors come out.
This's the dump script:
run "PGPASSWORD='#{remote_settings['password']}'
pg_dump -U #{remote_settings["username"]} #{"-h '#{remote_settings["host"]}'"
if remote_settings["host"]}
'#{remote_settings["database"]}' > #{remote_sql_file_path}"
There's some codes to transport..
Transport codes
And this's the restore script:
run_locally "PGPASSWORD='#{local_settings['password']}' psql -U
#{local_settings["username"]} -d #{local_settings["database"]}
-f #{local_sql_file_path}"
I get the data file successfully, but when there're some ERRORs* when **restore script is run:
psql:tmp/production-ib5k_production-2013-02-21_18:42:09.sql:46: ERROR: relation "refinery_images" already exists
psql:tmp/production-ib5k_production-2013-02-21_18:42:09.sql:49: ERROR: role "ib5k" does not exist
psql:tmp/production-ib5k_production-2013-02-21_18:42:09.sql:60: ERROR: relation "refinery_images_id_seq" already exists
psql:tmp/production-ib5k_production-2013-02-21_18:42:09.sql:63: ERROR: role "ib5k" does not exist
psql:tmp/production-ib5k_production-2013-02-21_18:42:09.sql:83: ERROR: relation "refinery_page_part_translations" already exists
psql:tmp/production-ib5k_production-2013-02-21_18:42:09.sql:86: ERROR: role "ib5k" does not exist
...
sql:tmp/production-ib5k_production-2013-02-21_18:42:09.sql:525: ERROR: duplicate key value violates unique constraint "refinery_images_pkey"
DETAIL: Key (id)=(1) already exists.
CONTEXT: COPY refinery_images, line 2: ""
psql:tmp/production-ib5k_production-2013-02-21_18:42:09.sql:547: ERROR: duplicate key value violates unique constraint "refinery_page_part_translations_pkey"
DETAIL: Key (id)=(1) already exists.
CONTEXT: COPY refinery_page_part_translations, line 8: ""
psql:tmp/production-ib5k_production-2013-02-21_18:42:09.sql:569: ERROR: duplicate key value violates unique constraint "refinery_page_parts_pkey"
DETAIL: Key (id)=(1) already exists.
CONTEXT: COPY refinery_page_parts, line 8: ""
...
And the database in local will not be updated.
I want to know how to solve it? Adding some arguments? Thank you in advance.
You can use the -c or --clean argument to pg_dump. That argument will drop existing database objects before running the commands to create them.
An alternative is to drop those objects yourself before restoring. (Probably using drop schema or drop database.)
Use with caution.
Related
I'm currently installing Nominatim using the Docker image that can be found at https://github.com/bringnow/docker-nominatim . However, when I send a query I get the following error:
Bad Request
Nominatim has encountered an error with your request.
Details: Illegal query string (not an UTF-8 string): paderborn
When I have a look at the console, I get the following error:
ERROR: relation "query_log" does not exist at character 13
STATEMENT: insert into query_log values ('2018-05-23 15:25:03.9961','paderborn','172.18.0.1')
ERROR: relation "new_query_log" does not exist at character 13
STATEMENT: insert into new_query_log (type,starttime,query,ipaddress,useragent,language,format) values ('search','2018-05-23 15:25:03.9961','q=paderborn&polygon=1&viewbox=','172.18.0.1','Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0','short_name:de,short_name:en-US,short_name:en,name:de,name:en-US,name:en,place_name:de,place_name:en-US,place_name:en,official_name:de,official_name:en-US,official_name:en,short_name,name,place_name,official_name,ref,type','')
ERROR: function make_standard_name(unknown) does not exist at character 8
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
STATEMENT: select make_standard_name('paderborn') as string
I already found an answer that proposes the following solution:
./utils/setup.php --create-functions --enable-diff-updates
However, this results in an error:
Functions
CREATE FUNCTION
ERROR: could not access file "/app/module/nominatim.so": No such file or directory
When I have a look at the file system, the file nominatim.so exists. So, this error is confusing.
Does anyone know a solution for that?
I found the mistake: We have two docker images, one for nominatim and one for postgis. The file /app/module/nominatim.so is created inside the nominatim image but also needed within the postgis image. The solution is to create a volume that allows to share the file.
Within docker-compose.yaml add the following lines to the nominatim service:
volumes:
- ./volumes/module:/mnt/module
and the following lines within postgis service:
volumes:
- ./volumes/module:/app/module
Further extend the entrypoint.sh:
log_info "==> Copy nominatim.so"
cp /app/module/nominatim.so /mnt/module/nominatim.so
Note that you have to rebuild the nominatim Docker image.
When I make a database in Ruby, based on the Heroku instruction, I have to command like this:
heroku run rake db:migrate
So when I did this, my entries that are stored in my local pc weren't transferred to Heroku. So, after searching for the way how I can do this, I saw this method.
Dumping the database file.
Setting heroku
heroku pg:push mylocaldb HEROKU_POSTGRESQL_MAGENTA --app sushi
sushi = my app name in Heroku.
When I tried to do this, the below error occured: TOC entry error, owerner of extension plpqsql error.
...
pg_restore: [archiver (db)] Error while PROCESSING TOC:
pg_restore: [archiver (db)] Error from TOC entry 2257; 0 0 COMMENT EXTENSION plpgsql
pg_restore: [archiver (db)] could not execute query: ERROR: must be owner of extension plpgsql
Command was: COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';
..
WARNING: errors ignored on restore: 1
I make the database file by
pg_dump databasenamehere > databasedumpfile
And I found the "databasenamehere" in /config/database.yml,,, development name.
This keeps happening and I don't know what to do.. :(
How can I solve this issue?
Is there any good method to put the entries to the HEROKU?
Also, why rake:db:migrate didn't push the entries to heroku? ( thinking this is a rookie question )
I am completely new to Postgresql, Postgis, and SQL and have a little bit of Rails knowledge. I am trying to get an existing app going on my local and am currently receiving the following messages when running a rake task to set up my database.
Blane-Cordess-MacBook:ajungo blanecordes$ rake postgres:create_postgis_template --trace
(in /Users/blanecordes/ajungo)
** Invoke postgres:create_postgis_template (first_time)
** Execute postgres:create_postgis_template
Enter your postgres username: blane
Password for user blane:
psql (9.2.1, server 9.1.4)
WARNING: psql version 9.2, server version 9.1.
Some psql features might not work.
You are now connected to database "template1" as user "blane".
psql:assets/sql/postgis_template_osx.sql:2: ERROR: permission denied to create database
psql:assets/sql/postgis_template_osx.sql:6: ERROR: permission denied for relation pg_database
psql:assets/sql/postgis_template_osx.sql:7: \connect: FATAL: database "template_postgis" does not exist
My postgis_template_osx.sql file is the following:
\c template1
CREATE DATABASE template_postgis WITH template = template1;
-- set the 'datistemplate' record in the 'pg_database' table for
-- 'template_postgis' to TRUE indicating its a template
UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template_postgis';
\c template_postgis
CREATE LANGUAGE plpgsql ;
\i /usr/local/Cellar/postgis/2.0.1/share/postgis/postgis.sql;
\i /usr/local/Cellar/postgis/2.0.1/share/postgis/spatial_ref_sys.sql;
-- 1.5.2
-- in a production environment you may want to
-- give role based permissions, but granting all for now
GRANT ALL ON geometry_columns TO PUBLIC;
GRANT ALL ON spatial_ref_sys TO PUBLIC;
-- vacuum freeze: it will guarantee that all rows in the database are
-- "frozen" and will not be subject to transaction ID wraparound
-- problems.
VACUUM FREEZE;
The PostgreSQL ROLE blane does not have permission to create databases. Either ALTER blane and add the CREATEDB option or use an existing administrator role that has that capability.
postgres=# ALTER ROLE blane WITH CREATEDB;
I am getting the following uuid error while running a rails app with postgres as backend. Can someone help me out with which dependency is needed.
[root#localhost webapp]# rake db:migrate
(in /root/mysite/webapp)
== CreateContributors: migrating =============================================
-- create_table(:contributors, {:id=>false})
-> 0.0121s
-- execute("alter table contributors add primary key (id)")
NOTICE: ALTER TABLE / ADD PRIMARY KEY will create implicit index "contributors_pkey" for table "contributors"
-> 0.0797s
-- execute("alter table contributors alter column id set default uuid_generate_v1()::varchar")
rake aborted!
An error has occurred, this and all later migrations canceled:
PGError: ERROR: function uuid_generate_v1() does not exist
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
: alter table contributors alter column id set default uuid_generate_v1()::varchar
The uuid_generate_v1() function is part of the uuid-ossp package and you have to install that into PostgreSQL before you can use it. You should have a file called uuid-ossp.sql in your PostgreSQL contrib directory. You can install the package with:
$ psql -d your_database < /the/path/to/uuid-ossp.sql
You'll probably want to run that as the database super user.
I'm trying out symfony so i started installing it on a remote mashine thru ssh (normal user, no root access)
when getting to the part where i want to generate the db-schema out of a existing mysql database with doctrine by issuing the following command:
./symfony doctrine:build-schema
i get the following errors:
Warning: require_once(): '/tmp/tmp_doctrine_models/User.php' is not a valid path for inclusions, since it includes /tmp/ in /home/users/mpretftp/test1/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Core.php on line 668
Warning: require_once(/tmp/tmp_doctrine_models/User.php): failed to open stream: Success in /home/users/mpretftp/test1/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Core.php on line 668
Fatal error: require_once(): Failed opening required '/tmp/tmp_doctrine_models/User.php' (include_path='.:/usr/share/php:/usr/share/pear') in /home/users/mpretftp/test1/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Core.php on line 668
by 'doing it the other way around', create the database.yaml like this:
User:
actAs: { Timestampable: ~ }
columns:
id: { type: integer, notnull: true }
hash: { type: string(255), notnull: true }
then trying out ./symfony doctrine:build --model i'm getting the following, even weirder error:
./symfony doctrine:build --model
>> doctrine generating model classes
>> file+ /tmp/doctrine_schema_70737.yml
Invalid schema element named "0" at path "Warning"
also, the hoster (of the remote mashine) has a comment on a joomla-error message. On one side i realize that joomla has nothing to do with symfony nor doctrine. But the error message resembles the first warning i pasted above: "... is not a valid path for inclusions,since it includes '/tmp/' in ....". The suggested sollution for the joomla-error is changing the /tmp/ path to /home/users/user/tmp in the joomla configuration
my best guess would be that i need to convince doctrine to use another path as well. unfortunatly i cannot find such a configuration option for doctrine.
could anyone either tell me how to set the tmp path for doctrine/symfony or php or even the enviroment?, or where to continue 'debugging'?
Doctrine uses PHP's sys_get_temp_dir to determine the temporary path. I found this out by search the Doctrine source for 'tmp_doctrine_models'.
It seems a little strange that your host doesn't allow the temporary directory to be written.