I can not see Turkish special characters on Amazon RDS PostgreSQL database. My development database displays characters properly.
When I connect to RDS instance via pgAdmin, I see ■aja²a³aa#test.com instead of şajaıaüağaç#test.com.
My server encoding and collate are UTF8 and en_US.UTF-8, respectively.
In database.yml file I set encoding to utf8.
default: &default
adapter: postgresql
encoding: utf8
There isn't any problem on my development database which is also PostgreSQL.
What am I doing wrong?
As far as I can remember, AWS RDS creates databases in latin1 encoding by default. Make sure your DB's and created tables' encoding is set to utf-8.
Related
our contract with a outsourced company fell apart, and they seemed to access the rails console in production. We have a backup, we are able to restore the data. But we need to make sure that who accessed the rails console.
development:
adapter: postgresql
encoding: unicode
database: xxxx-xxx
host: xxx.xx.xx.xx
pool: 5
username: xxxx
password: xxxx
in host if we change the ip, and give the appropriate user name and password, we will be able to connect to production data.
So is there a way, we can see the logs of who accessed the database through console?
ps: SSH into server is not possible as the passwords are changed recently.
So is there a way, we can see the logs of who accessed the database through console?
About the only log where this can be stored is your DB server log (in form of "open new connection from XXX.XXX.XXX.XXX"). That's as far as you can get, I think.
In any case, tracking rails console access doesn't make sense. Rails console can only access data if credentials in database.yml are valid. And if credentials in their database.yml are valid, they don't need the rails console to do all kinds of nasty things to your DB. They can just use psql directly or any other client.
Change DB credentials immediately.
Our database.yml is added to .gitignore so devs can customize local environments and we plan to use ENV['DATABASE_URL'] for production servers. For default setup, this works. However, we need to configure encoding and collation to utf8mb4.
encoding: utf8mb4
collation: utf8mb4_unicode_ci
I tried padding it to query parameters, like the ?pool=5 example in the docs, but it doesn't seem to work.
DATABASE_URL=mysql2://user:passwd#host:port/dbname?encoding=utf8mb4&collation=utf8mb4_unicode_ci
The tables created are still using the default encoding/collation so I assume the parameters doesn't work. Is there any way I could configure this by any other methods? Encoding and collation is the same for all environments.
Requirement is that dev environment can have a file with a config whereas prod should have no special file added, it should only use ENV variables. Maybe add this to one of the files inside config dir like application.rb or other files?
Thanks in advance.
PS: I'm new to Rails and Ruby (1 week) since I'm coming from PHP/Python.
You shouldn't specify any of the configuration options in the ENV variable. You should keep it clean and specify these options in database.yml file:
production:
encoding: utf8mb4
collation: utf8mb4_unicode_ci
pool: 5
The way it works is that rails takes what it can from the DATABASE_URL, and then applies options configured in database.yml for specified environment. If you want to learn more, follow this link: https://devcenter.heroku.com/articles/rails-database-connection-behavior#rails-4-1-and-beyond
I'm trying to connect my Rails app to an EC2 instance that contains a PG database. I've already checked with Navicat that I can connect to the database given the EC2 details. The issue is that when run locally the Rails app can't be viewed; it throws the error "database configuration does not specify adapter". A similar issue is thrown when I try a database migration. I haven't even tried to push this up to my Rails EC2 since it isn't working locally.
My database.yml file looks like this:
production:
adapter: postgresql
encoding: unicode
database: postgres
host: ec2-54-197-115-117.compute-1.amazonaws.com
pool: 10
port: 5432 (have both included and removed this line)
username: a database username for security
password: the password associated with that user
My gem files include the gem pg.
For the database name I just wrote what it had in Navicat, but perhaps there's an official name associated with it I should be using; if so, how would I find it? The host I got from the EC2 details. And the username and password were the ones I set with the postgres database via unix.
Thanks in advance for any insight!
Edit:
Fixed!
Fixed! I had forgotten to create an actual DB after setting up the PG; I changed the name in my database.yml file to reflect the new db name. Also, I needed to set on my Rails app environment directly (I thought Apache did this automatically w/Passenger) with "export RAILS_ENV=production". I thought it was still broken when I restarted my server and nothing had changed, but I just had to restart the console. Hope this helps someone else out too!
So, I'm fairly new to dealing with databases, and it makes sense to me when the database is on the local machine. But, how would I deal with a database that is far away/in a different computer? How is the connection set-up? How would I be able to tell Ruby to go toy with that database? I think SQLite is required to be on the local machine, but what about PostgreSQL or MySQL? I'm positive large projects require this sort of set-up with databases somewhere else and whatnot.
Also, this means teams should be able to all interact with the same database, correct?
I've tried finding articles and reading about it, but I can't seem to find any information about this.
In ruby on rails, we have a config/database.yml file where we can do database connectivity.
To connect to the remote system's database do:
1 - Give permission to your system to access the database of remote system
Grant all on databasename.* to username#ipaddress of your system identified by password
2 - Update the database.yml file
development:
adapter: mysql
database: databasename
username: username
password: password
host: ip of remote system
Configuring database.yml for your rails app
development:
adapter: mysql
database: development_database
username: root
password: [password]
host: localhost
test:
adapter: mysql
database: test_database
username: root
password: [password]
host: localhost
production:
adapter: mysql
database: production_database
username: root
password: [password]
host: localhost
Don't forget that these databases are not just files that the local program accesses -- they are servers in their own right, and the local program submits requests (select, insert etc) to them for the database server to process and return a result.
This also explains why multiple teams can access the same database -- the database server processes are just communicating with multiple programs at the same time (and the resolution of which program sees which data when they are all accessing and changing the same tables is one of the reasons why databases are so complex).
So the location of the database is only relevant in that it can take longer to send requests to, and retrieve results from, it over the network.
We're running a Rails app on Heroku and have it connected to a database on Amazon RDS. It works fine, the security zone is configured and the app is live.
Heroku requires you to provide a Database URL in the format of
mysql2://user:pass#rdsinstance.com/database
Since we're specifying the DB info in the add-on, what do we need to provide in the database.yml file, if anything?
Would the following suffice, or do we need even less than that? Maybe just the adapter name?
production:
adapter: mysql2
encoding: utf8
reconnect: false
pool: 5
Heroku automatically replaces the content of any database.yml file on deploy with the value of the shared database, normally stored in the SHARED_DATABASE_URL config variable.
I don't know if it's save to override that value. If you do it, you should be able to connect to the database from Rails without any additional effort.
If your app is working fine and you are just wondering what you need to write inside the default database.yml file, then you can put in whatever you want, Heroku will replace it in any case on deploy.