rake db:create fails, authentication problem with postgresql 8.4 - ruby-on-rails

first things first, please excuse my utter noobness. I really tried to find a solution out there, but now i'm stuck and completely clueless.
i'm trying to deploy a rails 3 app on a distant server ; when developping on my local VM, no problem showed. But now, when i try to run
rake db:create
it fails, with error (here translated, since i'm french):
FATAL : password authentication failed for user <<mylogin>>
here's my database.yml :
login: &login
adapter: postgresql
username: mylogin
password: mypassword
host: localhost
port: 5432
encoding: UTF8
development:
<<: *login
database: somesite_development
test:
<<: *login
database: somesite_test
production:
<<: *login
database: somesite_production
the user "mylogin" has been created postgre-side with the command-line tool "createuser". It's authorized to create dbs.
postgresql.conf configures the server to listen on localhost.
I've tried many things with pg_hba.conf, none worked - whatever the method used (ident, password, md5) for user "mylogin" on 127.0.0.1, authentication fails - though i've never had problems connecting / creating dbs with psql.
any clue ?
EDIT: okay, found out how incredibly stupid i've been... the password for my user was simply not set !
I think i forgot the semicolon after
ALTER USER xxxx WITH PASSWORD xxxx ;
... i saw this by requesting "SELECT * FROM pg_shadow;" - the password field was empty. Three days of my life wasted because of this dumb mistake...

I was also stuck on this problem for a really long time, and went to a variety of links (including the ones offered in this post) to try and find the answer, but to no avail. However, the solution is very simple. While many of the other responses were on the right track here are the exact steps to solve the problem:
Open your pg_hba.conf file in a text editor of your choice. (It is located in /etc/postgresql//main)
Navigate to the line that reads:
# "local" is for Unix domain socket connections only
and paste below it:
local all all trust
This will trust all unix users trying to connect to the psql server on the local machine. (Read documentation at top of page for further info about function of columns)
Save the pg_hba.conf file and exit the text editor.
Restart the Postgresql server by running the command:
service postgresql restart
Now try and start a psql server by running:
psql -d -U (or "psql " for short)
You should be able log in with no problem.
*Note:
All this assumes that you have have a valid psql username for logging in. If you don't follow the links below to set one up:
Setting up a user:
http://erikonrails.snowedin.net/?p=274
Making sure you have a valid postgres user:
http://archives.postgresql.org/pgsql-novice/2002-08/msg00072.php
Listing all existing psql users:
If you are looking for a "LIST USERS" or "DISPLAY USERS" command then try:
"select * from pg_user;" (when logged in to psql)
Good luck!

okay, found out how incredibly stupid i've been... the password for my user was simply not set ! I think i forgot the semicolon after
ALTER USER xxxx WITH PASSWORD xxxx ;
... i saw this by requesting "SELECT * FROM pg_shadow;" - the password field was empty. Three days of my life wasted because of this dumb mistake...

I had same problem. In my case it was because in my database.yml file the username started with capital letter but in database it was all lower case.
Solution: When creating user from postgres command line, it converts all letters to lowercase. For using capital letters, double quotes must be used.
Example:
create user AlbertEinstein; result = alberteinstein
vs
create user "AlbertEinstein"; result = AlbertEinstein

Here are some concise instructions that should work for you
http://www.cyberciti.biz/faq/psql-fatal-ident-authentication-failed-for-user/.
Basically you need to set the authentication method for localhost to 'trust'.

You need to give "myuser" in postgresql the privilege "Can create database objects".
In pgadmin, it looks like this:
After calling rake db:create, you can take away this privilege.

In my case, I found that a later host permissions rule line in the pg_hba.conf file had over-ridden the earlier local line. I was correctly configuring the local line to use md5 authentication but the host line was set to ident which I changed to md5
As other have emphasized here, note that using trust is an insecure method, so you shouldn't use it in any production-style deployment.

Related

Inexperienced Rails User: Wanting to Connect PostgreSQL to Already Existing App: Server Will not Connect

Optional Background: Hello, I’m quite new to the services on google cloud..well, and web development in general (Let’s say my training thus far is less than 60 hours on the rails framework and I’m not used to MVC or using databases at all. “Good luck kid”, I know.) My task is to deploy a mostly-done rails app that runs on Heroku to Google app engine. The app “builds” (after using gcloud app deploy), but it won’t connect to any database. Some of the files for doing that that I think should be there are missing. Namely, the config/database.yml file.
I thought it would make sense to just learn with a tutorial how you even connect a database on Google to an already existing rails app. I know rails generally just sets you up with a sqllite system automatically. But how do I write my own database.yml file to work on google app engine? And later on, how do I import all the information from our prior database...questions questions
Question Starts Here So, I started following this tutorial on the google cloud shell:
Pg 1: https://cloud.google.com/ruby/getting-started/tutorial-app I started here.
Pg 2: https://cloud.google.com/ruby/getting-started/using-structured-data Got here and decided on postgresql as my choice
Pg 3: https://cloud.google.com/ruby/getting-started/deploy-postgres and ran into an error where it tells me to call $: rake db:migrate
Here is the error message:
:~/projects/Bookshelfapp/getting-started-ruby/2-postgresql$ rake db:create could not connect to server: Connection timed out
Is the server running on host "35.193.145.252" and accepting TCP/IP connections on port 5432?”
Am I not connected to the database at all? I'm looking at my database.yml file.
Here is the format I was supposed to follow:
postgresql_settings: &postgresql_settings
adapter: postgresql
encoding: unicode
pool: 5
username: postgres
password: secret123
host: 173.194.230.44
database: bookshelf
Here is how I went for it: My database.yml file:
postgresql_settings: &postgresql_settings
adapter: postgresql
encoding: unicode
pool: 5
username: postgres
password: [my password is here]
host: 35.193.145.252
database: bookshelf
development:
<<: *postgresql_settings
production:
<<: *postgresql_settings
test:
adapter: sqlite3
pool: 5
timeout: 5000
database: db/test.sqlite3
Here is where I found the username and password:
username and password page
And I picked this IP address for the host:
IP address page
What am I doing wrong with my life? I haven’t assigned a static IP address to the VM, but I don’t really understand why I would do that.
Could anyone offer any suggestions of what to check for. I spent quite a bit of time going back into early steps and trying to find where I might have misstepped, but my inexperience isn’t offering too many solutions. Even routes to understand this problem better conceptually might help. I am not sure if I don’t know how to use some tool or if I have a big concept missing.I have never done anything like this before.
This issue seems similar to the following past questions, but I'm not sure how much they match up with mine:
question 1
question 2
question 3
question 4
If that error appears, it means the virtual machine where the database is hosted is not being accessed correctly.
The IP address you need for connecting to the database is indicated when you use SSH to access the PostgreSQL instance you created with the launcher (check the IP address that appears under the Bitnami logo).
You also have to open the server port for remote access, in this case 5432, which can be done with this command:
sudo ufw allow 5432
If you don't have ufw installed in the virtual machine, use apt-get to get it.
After that, restart the server to apply the changes, just in case:
sudo /opt/bitnami/ctlscript.sh restart
Besides, the firewall rule indicated in the tutorial is not well prepared, you have to remove the target-tags part. That way, you will be able to connect to the PostgreSQL database and continue the tutorial.

What steps should I follow to get postgresql into development in my Rails app?

I'm learning Rails and my final app will be hosted on Heroku, which uses postgres, so I figured it'd be smart to work with postgres in development too as I'm building what is supposed to be a rather simple search function and want to avoid as many problems as possible actually deploying it.
Sadly, I'm using Ubuntu 14.04 so naturally the steps will be harder than on for example Windows.
Here's what I've done so far, which is a rather comical enterprise into a world that gives me nothing but problems at every step:
Actually installed postgresql. sudo apt-get install postgresql-9.4 as per the official website of course didn't work so I had to find a workaround (as always) but it should be installed now. I ran sudo apt-get install -y postgresql postgresql-contrib to get it working.
Tried logging in per some instructions with su postgres, but even after setting a password for su or using sudo su postgres that didn't work. Ended up creating a user with sudo -u postgres createuser -P my_user matching the name of my app. Created a database too.
Tried creating a new rails project with rails new my_app --database=postgresql. Didn't work as it complained lacking a pg gem (sorry for not pre-emptively making a Gemfile for you?) so I gave that up and just created it without specifying a database.
Removed the sqlite gem and added gem 'pg' in the Gemfile. Ran bundle install, but it didn't work. Had to run sudo apt-get install libpq-dev to install something I'm not sure what it is and then it worked.
Modified the database.yml as per some instructions and ran rake db:setup. Rails gave this error: FATAL: Peer authentication failed for user "my_user". Well, that's cool.
Not quite sure why, but I added a database here called my_app_development for it with the owner my_user but then db:setup instead complained that it lacked permissions to create a database (but I just created it FOR you?).
I ran chmod -R 0666 my_app as someone highly upvoted on SO suggested but holy shit that was bad as it didn't even give me permissions to enter the folder myself! Reverted that quickly and tried something else.
Someone suggested running psql -U my_user postgres but that only gives me the error psql: FATAL: Peer authentication failed for user "my_user"
Experimented logging in via psql postgres (I don't know what psql is, I'm just following suggestions) and tried ALTER ROLE my_user CREATEDB; but it only returns a permission denied error.
Officially gave up and came here.
Can anyone help me with the actual steps to follow from the beginning? It shouldn't be THIS hard, right?
By the way, this is what my database.yml looks like:
default: &default
adapter: sqlite3
pool: 5
timeout: 5000
development:
adapter: postgresql
encoding: unicode
database: my_app_development
host: localhost
pool: 5
username: my_user
password: my_password
test:
<<: *default
database: db/test.sqlite3
production:
<<: *default
database: db/production.sqlite3
Edit: Thanks alot to Ajay for walking me through how to setup postgres. If anyone comes across this thread, as frustrated as I am with postgres, here are a few pointers:
PG::InsufficientPrivilege: ERROR: permission denied to create database means the user doesn't have the right privileges. Log in via sudo -u postgres psql and you should see postgres=# before everything you type in the terminal. While there, type ALTER ROLE my_user CREATEDB; and it should work. I don't know why it didn't the first time I used that, perhaps I forgot sudo?
FATAL: Peer authentication failed for user "my_user" means you need to change some things in a file as per the instructions in one of the answers. Make sure to change it for both local and postgres. I have it set to md5 for everything but local and it works.
Login via sudo -u postgres psql and type `select * from pg_catalog.pg_user;' to check your current users. Good way to see if you created the user correctly and what privileges it has.
default: &default
adapter: sqlite3
pool: 5
timeout: 5000
Above adapter: sqlite3 is causing the error
Please try this:
default: &default
adapter: postgresql
pool: 5
timeout: 5000
development:
<<: *default
database: my_app_development
username: psql #postgres username
password: your_password #password
After you entered the valid postgres credentials(username/password) here. Try following in your terminal :
$ rake db:create #this will create your my_app_development database.
$ rake db:migrate #migrate your database.
5. Modified the database.yml as per some instructions and ran rake
db:setup. Rails gave this error: FATAL: Peer authentication failed
for user "my_user". Well, that's cool.
you need to open your pg_hba.conf (probally located at /etc/postgresql/9.4/main/pg_hba.conf) and change the authentication method from "peer" to "md5" (which will asks for password) or to "trust" (which will unsecuritly allow access without password).
To know where your pg_hba is located, execute this on your terminal (terminal of the machine where the postgresql are running):
ps ax | grep postgresql.conf
it should return something like:
8803 ? S 0:00 /usr/lib/postgresql/9.4/bin/postgres -D /var/lib/postgresql/9.4/main -c config_file=/etc/postgresql/9.4/main/postgresql.conf
look the folder where config_file is located. In this case is /etc/postgresql/9.4/main/. Inside this folder there's another configuration file called pg_hba.conf (the permissions file). Edit it (with super user):
sudo nano /etc/postgresql/9.4/main/pg_hba.conf
on the lasts lines you will see something like that:
# DO NOT DISABLE!
# If you change this first entry you will need to make sure that the
# database superuser can access the database using some other method.
# Noninteractive access to all databases is required during automatic
# maintenance (custom daily cronjobs, replication, and similar tasks).
#
# Database administrative login by Unix domain socket
local all postgres trust
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres peer
#host replication postgres 127.0.0.1/32 md5
#host replication postgres ::1/128 md5
You see the "trust" references? In your default pg_hba.conf they should be "peer". In my example, I had changed to "trust" (i.e, doesn't ask for passwords) all local connections, because my postgresql server not accept outside connections. But you can change to "md5", which will permit access when the user provide the correct password.
After change this, save and exit (in nano is Ctrl+O, Enter to confirm, Ctrl+X to exit). Then, restart postgresql (sudo /etc/init.d/postgresql restart - maybe works with just a reload)
UPDATE:
DISCLAIMER:
although trusting your local connections will not create a hole security (unless, of course you are sharing the machine with anothers users), do it only for testing purposes - to discover where the problem is (if is a permission/pg_hba problem or not). After discover where the problem are, its more concise to have one specific user to your project and use an authentication for it ("md5", "peer").
Using one single user for all your projects on the machine (e.g. the "postgres" user), and/or not use an authentication ("trust"), is like create a Rails project and use just one generic controller, instead having a controller for each table/group of logic.

Not sure if my rails application is configured properly for posrtgres db

My problem: I have setup the dev, test environments of my Rails application to use the postgresql database. Now how do I verify that it is ok?
Note: I am beginner on Rails and using databases
What I've did to verify
I followed the railcast to migrate from default sqlite3 to postgresql.
I fired up the rails console and created a user using
User.create(name: "Anil Bande", email: "anil#gmail.com", password: "foobar", password_confirmation: "foobar")
From the output it looked like the user was created. To verify I ran $ User.all while on the rails console and the output displayed the object I'd created in step (2)
Now I wanted to see this from postgresql prompt. So I did $psql sample_app_development and there came the psql prompt.
I did a psql>> \d on the psql to list all the tables in the database. It did and the table "users" was also present in which I was interested in.
Now I did a psql>> select * from users , but there were no results. The prompt just returned back.
Now here is my confusion. Step (6) showing nothing. But in rails console it looks like the user is created and saved in the database.
(a) Why so?
(b) How do I verify everything I have done to setup the dev and test environment is correct?
I can't comment on the Rails part, but for this:
Now I did a psql>> select * from users , but there were no results. The prompt just returned back.
You forgot to end the statement with a ;
You need to tell psql when you are finished typing a statement, as it is allowed to have a statement span more than one line. Note how the prompt changed from psql=> to psql-> to indicate that psql is waiting for more.
So if you enter
psql=> select * from users;
you should be fine.
(Just to be clear: psql as part of the prompt is only an example. The real prompt will contain the name of the database you are connected to. The important thing to look for is the => and ->)
Have you run your migration on the DB yet in the console?
rake db:migrate
If so, also make sure that your database config yml file has the correct info with ->
user, password, localhost etc listed for your databases like
development:
adapter: postgresql
encoding: unicode
database: pg2_development
pool: 5
username: postgres
password: root
host: localhost
--> run rails server , than goto localhost:3000/user to check results
If you are just getting started with postgres you may find your general admin better served using a GUI interface like pgadmin
For example it would tell you that the end ';' was missing. It still allows you to go directly to a psgl command line.

Installing Postgres on windows for use with Ruby-on-Rails

Currently I get the following error:
PGError (FATAL: password authentication failed for user "postgres" ):
when my app tries to access the database.
I wanted to test my SQL calls against postgres as my app regular breaks when pushed up to production on Heroku because of the stricter requirements of postgres (which I think is probably a healthy thing) over sqlite 3. So I have a similar request to this for a not out of date tutorial for installing postgres for use with ruby on rails on windows (7) please. I thought it'd be a quick 20 minutes of downloading and installing but 2 and a bit hours later and I don't think I'm very close yet. So far I've:
Downloaded and installed Postgres Version 8.4.8-1 from here
Set my environment variables such that Path (for User) is: C:\Ruby192\bin;C:\Program Files (x86)\PostgreSQL\8.4\bin
Gemfile:
gem 'pg', '0.11.0' # instead of gem 'sqlite3', '1.3.3'
ran bundle install for my rails app seemingly successfully, but haven't found easy way to validate installation yet.
set database.yml as suggested here to:
development:
adapter: postgresql
database: db/development
username: postgres
password: secret
host: localhost
encoding: UTF8
pool: 5
timeout: 5000
I know I need to set up a user name and password for Postgres, maybe also start the postgres server, connect to it(?) and put in my local IP address I'll connect to it on into a config files somewhere and then edit one of the other .conf files in 'C:\Program Files (x86)\PostgreSQL\8.4\data' etc...
I think Rails has made me soft, am I over thinking things or is it actually fairly tricky to set up and I should just go back to Sqlite3, for which there's also the awesomely useful SQLite Manager, Firefox plugin?
I'm still searching for a beginners guide to installing and using Postgres for rails but so far have only been confused by most of the stuff I look at / tried following like this, this, this, this, this(for Snow Leopard), this(linux).
Any pointers would be much appreciated. Thanks!
James
An approach to installing Postgres on windows 7 for use as PostgreSQL database for a rails 3 (3.0.7) project.
Preamble (you can skip this bit)
So the first thing to point out is that Postgres is not just a different file extension from .sqlite3, it's a whole mechanism for managing your databases. As such it has a client/server model, of which you'll need to set up both to use Postgres as the database for your rails app.
Motivation for going through considerable pain of Postgres setup versus almost effortless sqlite setup: if you're deploying to Heroku, they're currently using Postgres so some of your SQL calls that are fine on sqlite3 will break when used with Postgres. It's much easier to debug postgres locally rather than when it's on Heroku's servers.
So I did the following things:
(Disclaimer: I may have forgotten to include some of the things I did... it took me over 48 hours of on and off pain to get it to work... if the following advice doesn't work for you then the huge (2300 pages!!) but very thorough Postgres documentation should help. I'd recommend downloading this anyway if you're serious about using Postgres as it has a lot of material that I've only just begun to understand the significance of.)
(Second disclaimer: I have almost certainly broken 20 sensible Postgres guidelines and exposed security holes in the Postgres database whilst doing so. If there any obvious things an experienced Postgres user disagrees with, please edit my post.)
.Step 1. Download and install PostgreSQL v9.0.4-1 from here because here said only 9.0.x would be supported on windows 7. I kept all the default options and just used 'secret' as the password when prompted by the Postgres installer for one (again not entirely sure what the consequences of sharing that info on the internet is... will soon find out I'm sure). You'll need this password in step 3.
.Step 2. Change environment variables such that Path (for system, not user (I'm not sure if this is significant or not)) is: C:\Program Files\PostgreSQL\9.0\bin
(n.b. I'm on 64-bit windows hence it not being installed for 32-bit in 'C:\Program Files (x86)\PostgreS...')
Don't forget to change access rights to folder PostgreSQL\9.0 and remove any default readonly rights on the folder or content.
(You may also need to restart your computer for these to take effect - thanks #Gavin -although not likely).
.Step 3. Test Postgres installation by trying to create a new database:
From command line: createdb -U postgres mydb_as_postgres.
You should be prompted to enter the password now, if you're not it may be that you need to start the server first (I can't remember whether I needed to do this or not). The easiest way is through pgAdmin III, which should be 'pgAdmin3.exe' in a folder somewhere like C:\Program Files\PostgreSQL\9.0\bin. Once you've started pgAdmin III there should be a panel on the left called 'Object Browser'. In this there should be a tree with:
Server Groups > Servers > PostgreSQL 9.0 (localhost:5432)
Right click on 'PostgreSQL 9.0 (localhost:5432)' and select 'Connect'.
The createdb -U postgres mydb_as_postgres command should create a new databse called 'mydb_as_postgres' which you can check by firing up pgAdmin III and double clicking on 'PostgreSQL 9.0 (localhost:5432)'. Under this there should be:
Databases (2) which should list 2 databases called mydb_as_postgres and postgres
I called it _as_postgres because the -U postgres part of the command tells Postgres to create the database with the postgres user as it's owner, which you need to specify when you're not signed in as the postgres user. I have all of my files stored as 'AJames' user though so if you're the same and want to keep developing your app when signed in as a different user you need to create a Postgres 'role' for that user now (see step 4).
.Step 4. Through pgAdmin III. Right-click on Login Roles (which for me is in):
Object Browser > Server Groups > Servers > PostgreSQL 9.0 (localhost:5432) > Login Roles
Right-click on Login Roles and select 'New Login Role...'
in Role name, put in your operating system user name, which for me is AJames,
and fill in your password under the 'Role Privileges' tab, I checked all the boxes, but an experienced postgres user would likely strongly recommend to only check the 'inherits rights from parent roles' and the 'can create database objects' But I'm not an experienced user and just want to debug Rails SQL calls in Postgres so I also checked the 'Superuser' and 'Can create roles', just in case.
.Step 5. You should now be able to create a new database without being signed in as the postgres user. Try typing:
createdb mydb_as_user
Hopefully this should work for you.
.Step 6. Okay, so you've got a development.sqlite3 file in your rails 'db/' directory. Initially I was going to set the next test as converting this from sqlite3 to psql.
I couldn't get this to work though but I left my attempts here as the solution I used required having the data in a Rails app on Heroku.com (see instead the solution from step 7 onwards). For those who only have a local app and no data in Heroku, they can't use the same approach, so they might need to explore something like this:
x6.1 First, test 'psql' by trying a command from your command line like:
psql mydb_as_user
this should display something like below (after you've typed in your password):
C:>psql mydb_as_user
Password:
psql (9.0.4)
WARNING: Console code page (850) differs from Windows code page (1252)
8-bit characters might not work correctly. See psql reference
page "Notes for Windows users" for details.
Type "help" for help.
mydb5=#
x6.2 try entering:
CREATE TABLE users_table (id integer, "name" text);
It should display:
CREATE TABLE
mydb5=#
If you check in pgAdmin III, you should see the table there under:
Object Browser > Server Groups > Servers > PostgreSQL 9.0 (localhost:5432) > Databases > mydb_as_user > Schemas > public > Tables > users_table >
x6.3 Okay, next to try the conversion. Downloaded sqlite-shell precompiled binary for windows.
x6.4 Create a new directory, I used 'C:\temp' and put the sqlite3.exe and your development.sqlite3 files in it.
x6.5 Use the following commands (which are from here) to dump the development.sqlite3 database into Postgres.
sqlite3 development .dump | psql development2
you might get an error like:
psql: FATAL: database "development2" does not exist
x6.6 so I went into pgAdmin III and made a development 2 database, tried the command again and got:
ERROR: syntax error at or near "PRAGMA"
LINE 1: PRAGMA foreign_keys=OFF;
^
BEGIN
COMMIT
Like I said, I couldn't get it to work. I'm sure there's a way of getting round that error but I thought of a different way and so I instead used this solution (which requires a Heroku account to have your data and does the conversion from sqlite3 to psql using the Taps gem (I believe):
.Step 7. in pgAdmin III I created another database. Under the properties tab I set name: 'development', owner: 'AJames' (replace this with your own Windows user name). And under the privileges tab, set role: 'public' and checked the ALL option (thought this resets to unchecked so I'm not sure that's necessary).
.Step 8. add
gem 'pg', '0.11.0'
to your gem file. You'll probably also want to remove the:
gem 'sqlite3'
at this point too.
.Step 9. set database.yml as suggested here to:
development:
adapter: postgresql
database: db/development
username: AJames # replace this with your own user name
password: secret # replace this with your own password
host: localhost
encoding: UTF8
pool: 5
timeout: 5000
If you are working on an open source project and don't want your password to be made publicly available, have a look at some of the answers to Securely providing the database password in a Rails app.
.Step 10. from command line in your rails app's root directory run:
rake db:migrate
This will create the new schema and all the tables in the Postgres database.
.Step 11. run heroku db:pull from your command line (again from in the root directory of your rails app) to pull all your data down and into your new empty Postgres database. I think at this point your taps gem will be doing this work for you.
.Step 12. Hopefully there is no step 12! ...and it should now be working for you. Happy RoR PostgreSQL debugging! Please edit, or let me know, if there are any errors in this.
Also, here's a list of additional stuff that might be interesting/useful:
This is a blog post about Postgres passwords, what they're for,
why you need them, how to change them etc.
This, under 'Creating a spatial database', is useful for newbies to
understand what pg_hba.conf is about and the second link that
Reno gave above, under the 'Using pgAdmin III GUI' is useful to
testing to see if postgres is actually working, before trying to fit
it with Rails (i.e. try creating a database and putting a table and
some data into it).
In the huge but very comprehensive Postgres documentation, I'd
start on page 58, 'I. tutorial'. Then on pdf page 431(!) there's
'Chapter 17. Server setup and operation' that I also found useful.
the answer from AJP is the correct one with just a small re-config.
The line
database: db/development
does not work for me.
I have to change it to
database: development
I use this for ruby on rails for the command
rake db:create
and
rake db:migrate
to work
None of your links appeared to be the (arguably) most useful documentation - the official postgresql docs. I recently configure a Linux Mint box with postgresql and django using a combination of those documents and these, though the latter are specific to Linux.
I'd worry more about validating the postgresql side of things, less about rails. That is to say, your question should be "How can I set up and test a postgresql server on a Windows 7 box", moreso than you need to know how to get it locked into rails.
Edit:
Maybe this could also be of use to you - official postgresql wiki with detailed installation guides.
Good luck!

Database not being selected in rails project when attempting to rake db:migrate

Working with a rails app, having some manner of weird database / rake issues.
When I execute:
rake db:migrate
I am getting the following error:
Mysql2::Error: No database selected: SHOW TABLES
(See full trace by running task with --trace)
The trace isn't revealing much useful information. Can be seen here: http://pastebin.com/WdsguudC
The config file looks right, and the user is getting logged in, or I would have gotten some kind of access error. The database exists, the user has correct permission, and I can access and manipulate it manually. I have done a bunch of googling, and haven't found anything helpful. Not sure if there is any other code that needs provided, because this seems like fairly low level problem.
after all that it was a spacing issue in the yaml.
Note that ruby has exchanged its YAML parser in a recent 1.9.2 version.
This might also cause this problem.
In order to switch back to the old YAML parser syck, use this in boot.rb:
require 'yaml'
YAML::ENGINE.yamler= 'syck'
Well, it is a common issue for us beginners. This issue comes from the moment when you create your new project in rails. Let’s say to have an example
$ rails new toy –d mysql
After you do the bundle and start your server, most likely you will have an error. To correct it you need to go to your database.yml and modify the following:
Add a password in the password field as shown below, this is the password you use to secure mysql.
default: &default
adapter: mysql2
encoding: utf8
pool: 5
username: root
password: mypassword
socket: /tmp/mysql.sock
Also, comment out the database adding a hash tag (#)before the name as shown below
development:
: *default
database: #toy_development
Then restart your command line and go to the root of your application and type:
$ rails s
You have to see the Ruby on Rails welcome page..
After, you need to create a database.
Create a DATABASE.
The issue message is saying that not DATABASE is selected. It is because I didn’t create one. When you work with MySQL you have to create one, so:
Go to the root of my application and type:
$ mysql –u root –p
$ Passwor: mypassword (Enter your password, this is the one you entered to secure MySQL)
Note: This example works wit a project called toy and the user I wanted to grant privileges is mark and the password I’ll give is 45mark. Below you will see where I apply these elements. Remember to apply your own elements on each part of the statement.
Create and user for this project
Once you are in, you will see the pointer (mysql> ), so type after it:
mysql> GRANT ALL PRIVILEGES ON toy_development.* TO 'mark'#'localhost' IDENTIFIED BY '45mark';
Then type:
mysql> exit;
Check that it is working by typing:
$ mysql –u mark –p toy_development
Enter password: 45mark (You enter the one you gave)
Open database.yml file and configure what is needed and fix as required. In my case I will chance the username to mark and the password to 45mark
default: &default
adapter: mysql2
encoding: utf8
pool: 5
username: mark
password: 45mark
socket: /tmp/mysql.sock
- Also, REMOVE the hash tag (#) added before
development:
: *default
database: toy_development
Save it.
Go to the root of the application and type
$ rake db:schema:dump
Done!!
I hope this helps. Happy coding!!
Thanks
I had the same issue with ruby 1.9.2-p180 , upgraded to p290 and it works
Just restart the server; in the command line:
Press Ctrl + C
execute:
rails s
I had a similar error when i typed rake db:schema:dump and it turns out that I just have to comment out all the databases on my yaml file except my development one.
Give a try to this.
rake db:test:prepare
Install this to see if you have actually created a table or not. Open the "development.sqlite3" in db folder
http://sqlitebrowser.org/
Its a simple error checkout the entire database.yml file and see that where is default decription is given database name is given or not if not then look below it there will another development name is also given where configuration of database is use check that give your database name in it
default: &default
adapter: mysql2
encoding: utf8
pool: 5
username: root
password: 12345
host: localhost
development:
<<: *default
database: db_name
One potential cause is that there is a DATABASE_URL environment variable defined.
$ echo $DATABASE_URL
=> mysql2://root#localhost:3306
If you get a similar output to the above url (i.e., the database name is not present), then you might want to add the database name to the string or unset the env var.
$ export DATABASE_URL=mysql2://root#localhost:3306/my_rails_app_development
$ unset DATABASE_URL
If you unset the var, you probably want to specify the database details in database.yml instead.

Resources