Rails 5 how to clear or delete production postgres database
Try this it worked for me: RAILS_ENV=production rake db:drop DISABLE_DATABASE_ENVIRONMENT_CHECK=1 in a single line.
Try this it worked for me: RAILS_ENV=production rake db:drop DISABLE_DATABASE_ENVIRONMENT_CHECK=1 in a single line.
ActiveRecord should preserve the full precision from the database, you’re just not looking at it properly. Use strftime and the %N format to see the fractional seconds. For example, psql says this: => select created_at from models where id = 1; created_at —————————- 2012-02-07 07:36:20.949641 (1 row) and ActiveRecord says this: > Model.find(1).created_at.strftime(‘%Y-%m-%d %H:%M:%S.%N’) => … Read more
You need to install the package postgresql-contrib-9.1 in your system first. (Adapt to your version number! Here is the currently available list of packages.) That’s the case under Debian, Ubuntu & friends anyway. Using a system user with the necessary privileges: apt-get install postgresql-contrib-9.1 If your currently logged in user does not have the necessary … Read more
You have to restart the Postgresql Server in order to load the shared library and afterwards execute CREATE EXTENSION pg_stat_statements; in the database you want to monitor. Additionally you will have to edit the following line in postgresql.conf shared_preload_libraries=”” To shared_preload_libraries=”pg_stat_statements” A restart of the PSQL service is required.
ActiveRecord .create method supports bulk creation. The method emulates the feature if the DB doesn’t support it and uses the underlying DB engine if the feature is supported. Just pass an array of options. # Create an Array of new objects User.create([{ :first_name => ‘Jamie’ }, { :first_name => ‘Jeremy’ }]) Block is supported and … Read more
For any who stumbles upon this. I have come up with a list of queries using ActiveRecord and Postgres’ JSON data type. Feel free to edit this to make it more clear. Documentation to the JSON operators used below: https://www.postgresql.org/docs/current/functions-json.html. # Sort based on the Hstore data: Post.order(“data->’hello’ DESC”) => #<ActiveRecord::Relation [ #<Post id: 4, … Read more
Try adding host: localhost to your database.yml. (Based on: https://stackoverflow.com/a/10793186/919641)
Basically what you want is: $ select starts_at AT TIME ZONE ‘UTC’ AT TIME ZONE ‘US/Pacific’ from schedules where id = 40 I got the solution from this article is below, which is straight GOLD!!! It explains this non-trivial issue very clearly, give it a read if you wish to understand pstgrsql TZ management better. … Read more
To solve the issue you must assign the proper ownership permissions. Try the below which should resolve all permission related issues for specific users but as stated in the comments this should not be used in production: root@server:/var/log/postgresql# sudo -u postgres psql psql (8.4.4) Type “help” for help. postgres=# \du List of roles Role name … Read more
It looks like in Ubuntu that header is part of the libpq-dev package (at least in the following Ubuntu versions: 11.04 (Natty Narwhal), 10.04 (Lucid Lynx), 11.10 (Oneiric Ocelot), 12.04 (Precise Pangolin), 14.04 (Trusty Tahr) and 18.04 (Bionic Beaver)): … /usr/include/postgresql/libpq-fe.h … So try installing libpq-dev or its equivalent for your OS: For Ubuntu/Debian systems: … Read more