Issues with setting PostgreSQL up and db:rake - sql

I've had numerous issues with setting up Postresql for a project I'm working on.
Some information:
-I'm running Ubuntu 12.04
-I have a postgres user account installed
-I'm trying to use a project in RoR.
I'm trying to use this command:
"bundle exec rake db:create"
I tried using it as sudo, computer user, and postgres.
When I run it as my computer user it returns "fe_sendauth: no password supplied" and then aborts the rake.
I know my (user account) ruby version is 2.1.0 because when I run "ruby --version", it returns
"ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-linux]"
However, when I run "ruby --version" as postgres, it returns
"ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-linux]"
How can I have separate ruby versions for my user account and postgres? I tried using sudo to change the ruby version with RVM, but I was denied permission.
I don't remember setting the password for postgres sudo, and I cannot figure it out.
What can I do to
Recover/reset my sudo postgres password.
Install/set the newest (2.1.0) version of ruby on the postgres account once I have done step 1.
Run bundle exec rake db:create after all of that?

Hm, not sure any specific issues with linux, but it sounds like you have it installed okay.
Hard to say without looking at your database.yml, but the rails convention seems to be to connect to the database with the username <%= your_project_name %> and a blank password. Based on the error, you may not have created such a user/role in postgres.
# enter the psql shell as the postgres admin user
psql -d postgres
CREATE ROLE <%= your_project_name %> WITH LOGIN CREATEDB SUPERUSER;
\q
# create the dbs and load the schema
bundle exec rake db:create
bundle exec rake db:schema:load
bundle exec rake db:migrate
bundle exec rake db:test:prepare
# revoke superuser, it was just there in case there were any extensions that needed installing
psql -d postgres
ALTER ROLE <%= your_project_name %> WITH NOSUPERUSER;
\q
That should do that trick, although it sounds like you might be having issues with RVM as well. There is a ton of documentation on RVM on the website.
You also may be confusing the concept of users/roles in the DB with the concept of users in the OS. You should be able to access the database with any unix user but you need to authenticate rails into the database using database.yml. As noted above, there seem to be defaults that most rails projects i've seen use, but of course you could use whatever you want.

Ok, so I fixed my main issue with my ruby version being incorrect and not being able to fix it because I did not have authentication.
I did this with
$ /bin/bash --login
This let me then type
$ rvm --default use 2.1.0
This set my ruby version in user postgres to 2.1.0.
However, I then tried to run
$ bundle install
in user postgres, and I was denied and given this error
Unfortunately, a fatal error has occurred. Please see the Bundler troubleshooting documentation at
http://bit.ly/bundler-issues. Thanks!
/home/myusername/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/fileutils.rb:250:in `mkdir': Permission denied # dir_s_mkdir - /home/myusername/.bundler (Errno::EACCES)
I cannot access sudo for user postgres because I did not set the password for it. therefore, I believe that the answer to my question is to run
$ sudo bundle install
but I do not have the sudo password.
Any help with this issue would be appreciated.

Related

Why do I keep getting this error on Postgreql psql: /lib64/libpq.so.5: no version information available (required by psql)?

Updated: Someone mentioned below this is a duplicate of this: https://dba.stackexchange.com/questions/269473/what-does-psql-usr-pgsql-11-lib-libpq-so-5-no-version-information-available Well mine is on centos and Below is what shows when I use: rpm -qa|grep postgres command.
postgresql-10.6-1.module_el8.0.0+15+f57f353b.x86_64
postgresql-server-10.6-1.module_el8.0.0+15+f57f353b.x86_64
I have been having these errors lately, I am accessing the server remotely and I have tried to search for ways to rectify this, yet I have not gotten a concrete way to do this: some people advised to reinstall the PostgreSQL but I am not too sure about this; As it stands now I don't really know what works here so I have decided to ask this: below is the error from the console;
[postgres#gma ~]$ psql
psql: /lib64/libpq.so.5: no version information available (required by psql)
psql: /lib64/libpq.so.5: no version information available (required by psql)
psql (10.6)
Type "help" for help.
When I used this command: yum list installed | grep postgres
I got this: `Modular dependency problems:
Problem 1: conflicting requests
nothing provides module(perl:5.26) needed by module perl-DBD-Pg:3.7:8010020200204214655:0d1d6681-0.x86_64
Problem 2: conflicting requests
nothing provides module(perl:5.26) needed by module perl-DBI:1.641:8010020191113222731:16b3ab4d-0.x86_64`
The Modular dependency problem is solved but it still shows the same error: I used this for resolving the modular dependency issue: <
root pass:# yum module enable perl:5.26
The reason why you are getting such error is because you have not mentioned the (-h) Host location of the database server(localhost if running locally) , (-u) username for the database access and (-W) to ask password in your psql command. After which it would look some what like this:
$psql -U {username} -h {host} -W
examples:
$psql -U jack -h localhost:5432 -W
$psql -U jack -h 54.261.74.39:5432 -W
Worked for me this way.

DB2 V10.5 db2setup hangs on ppc64

When using the db2setup (Wizard) to install a new version of DB2 V10.5.0.3 (or the universal fixpack V10.5.7) the installer appears to hang near the end of the Create DB2 Administration task. There is a das directory created in the /home/dasusrX directory but it has no visible files. The logs show no errors. Manually trying to create the DAS also hangs using dascrt -u dasusrX
In the console where I launched the db2setup I found I needed to enter the dasusrX password a couple of times. There is no prompt displayed. I believe the system also hangs during the Configuring DB2 instances task and luckily I used the same password for other users so I entered it there as well to complete the install.
I figured this out running the dascrt -d -u dasusrX and saw it hung at the su dasusrX -c /bin/pwd command and when I tried that command manually, it propmted for the dasusrX password. This may be a unique situation for our server set up as root is accessible only via sudo -i so perhaps in other situations there would be no prompt for dasusrX password when using su as root.

$ rails server... undefined method `gem' for main:Object (NoMethodError)

I'm new to Rails trying to complete this tutorial, but I can;t even get started.
http://ruby.railstutorial.org/ruby-on-rails-tutorial-book#sec-rails_server
I am at Step 1.2.5
I am supposed to start the server using: $ rails server
I'm getting this error whenever I try to run any rails command.
localhost:first_app home$ rails server
/usr/bin/rails:22: undefined method `gem' for main:Object (NoMethodError)
Running rails commands used to work, because I had completed other tutorials from other books in the past. However, somewhere along the steps in this tutorial something was messed up.
Is it possible that editing my bash_profile caused this?
My bash_profile looks like this now:
export PATH=/bin:/usr/bin:"$PATH"
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session.
I added this line to it: export PATH=/bin:/usr/bin:"$PATH" after following directions in step Listing 1.1. Creating a gem configuration file.
I'm not sure if this helps, but If I type:
$ which rails
I get:
/Users/home/.rvm/gems/ruby-1.9.3-p194#rails3tutorial2ndEd/bin/rails
Have you installed gem? type:
which gem
and see what you get. If you don't have gem or the wrong version, follow these instructions: http://ruby.railstutorial.org/ruby-on-rails-tutorial-book#sec-install_rubygems
typing
$ rvm use 1.9.3#rails3tutorial2ndEd --create --default.
allowed me to continue.
I had a similar problem under ubuntu. I fixed it by changing gnome-terminal settings https://rvm.io/integration/gnome-terminal

How can I get rails to use pg by default?

It's not a huge burden but I would really like to be able to change the default gem-set on my rails apps when I create them so that they're ready for Heroku.
What is the best way to go about doing this?
You can specify the database with -d when running rails new:
Usage:
rails new APP_PATH [options]
Options:
-d, [--database=DATABASE] # Preconfigure for selected database (options: mysql/oracle/postgresql/sqlite3/frontbase/ibm_db/sqlserver/jdbcmysql/jdbcsqlite3/jdbcpostgresql/jdbc)
# Default: sqlite3
Description:
You can specify extra command-line arguments to be used every time
'rails new' runs in the .railsrc configuration file in your home directory.
So for PostgreSQL this is:
rails new myapp -d postgresql
To make this the default put -d postgresql into ~/.railsrc
Another option is to change gem 'sqlite3' to gem 'pg' in your Gemfile as suggested in Getting Started with Rails 3.x on Heroku.

RVM & Unicorn deploy

My RVM is installed as root.
When I'm trying to start unicorn socket, it prints
user#9001-3:~$ /etc/init.d/unicorn start
Starting myapp app: /usr/bin/env: ruby: No such file or directory
unicorn.
But if I type
user#9001-3:~$ ruby -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]
/usr/local/rvm/gems/ruby-1.9.2-p180/bin/unicorn path exists.
My unicorn config: https://gist.github.com/1010519
/etc/init.d/unicorn doesn't know where to find Ruby because it's managed via RVM. Normally, your .bashrc or similar file is executed and sets up the environment; this doesn't happen in init scripts (or likely anything else executed by root).
The solution is to use wrappers. For example, to create a binary called system_ruby that loads up RVM's 1.9.2p180 environment and then executes ruby, execute the following:
rvm wrapper ruby-1.9.2-p180 system ruby
For more information and more details, check out this answer of mine, which addresses a similar problem.
Symlink also works,
which ruby<your version>
ln-s /ruby/path/ruby<your version> /ruby/path/ruby
Type :
which ruby (show the ruby bin path) then type this : ln -s (change_to_ruby_path) /usr/bin/env/ruby (construct the correct access for your system)
I had the same problem and this for me
rvm --default use <version>