Trying to start Ruby on Rails app with Postgresql --noob - ruby

This is my 3rd day in a row trying to start a new app using Postgresql w/ Ruby on rails with wsl ubuntu.....(i'm on windows)
I'm a beginner. I've learned the basic syntax, but getting a practice app running on Postgres i just cant seem to do it. ill literally pay for help if someone can help me out.
Everytime i try to start the database i get
chronokross#DESKTOP-V7DS5HD:/mnt/c/code/nathantest$ rake db:create
Database 'chrono_development' already exists
could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
Couldn't create 'chrono_test' database. Please check your configuration.
rake aborted!
ActiveRecord::NoDatabaseError: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
Caused by:
PG::ConnectionBad: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
Tasks: TOP => db:create
(See full trace by running task with --trace)
chronokross#DESKTOP-V7DS5HD:/mnt/c/code/nathantest
I've followed millions of guides. I dont know how to connect postgresql on windows to my ubunix server ROR app.
my discord is ChronoKross#1560.
They say to edit my databse yml file. This is how i did it
# PostgreSQL. Versions 9.3 and up are supported.
#
# Install the pg driver:
# gem install pg
# On macOS with Homebrew:
# gem install pg -- --with-pg-config=/usr/local/bin/pg_config
# On macOS with MacPorts:
# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
# On Windows:
# gem install pg
# Choose the win32 build.
# Install PostgreSQL and put its /bin directory on your path.
#
# Configure Using Gemfile
# gem 'pg'
#
default: &default
adapter: postgresql
encoding: unicode
# For details on connection pooling, see Rails configuration guide
# https://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
development:
<<: *default
database: chrono_development
# The specified database role being used to connect to postgres.
# To create additional roles in postgres see `$ createuser --help`.
# When left blank, postgres will use the default role. This is
# the same name as the operating system user running Rails.
username: chronokross
# The password associated with the postgres role (username).
password: *****
# Connect on a TCP socket. Omitted by default since the client uses a
# domain socket that doesn't need configuration. Windows does not have
# domain sockets, so uncomment these lines.
host: localhost
# The TCP port the server listens on. Defaults to 5432.
# If your server runs on a different port number, change accordingly.
#port: 5432
# Schema search path. The server defaults to $user,public
#schema_search_path: myapp,sharedapp,public
# Minimum log levels, in increasing order:
# debug5, debug4, debug3, debug2, debug1,
# log, notice, warning, error, fatal, and panic
# Defaults to warning.
#min_messages: notice
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: chrono_test
# As with config/credentials.yml, you never want to store sensitive information,
# like your database password, in your source code. If your source code is
# ever seen by anyone, they now have access to your database.
#
# Instead, provide the password or a full connection URL as an environment
# variable when you boot the app. For example:
#
# DATABASE_URL="postgres://myuser:mypass#localhost/somedatabase"
#
# If the connection URL is provided in the special DATABASE_URL environment
# variable, Rails will automatically merge its configuration values on top of
# the values provided in this file. Alternatively, you can specify a connection
# URL environment variable explicitly:
#
# production:
# url: <%= ENV['MY_APP_DATABASE_URL'] %>
#
# Read https://guides.rubyonrails.org/configuring.html#configuring-a-database
# for a full overview on how database connection configuration can be specified.
#
production:
<<: *default
database: chrono_production
username: chronokross
password: *****
PLEASE PLEASE I BEG FOR HELP. I've been studying 8hrs a day but this is a HUGE road block, i need someone to tell me what to do in noob terms or screenshare with me.
again my discord is ChronoKross#1560

Related

Dropwizard crashing on Heroku

I am trying to deploy my Dropwizard project to Heroku.
I have added a Procfile and a Postgres DB to the Heroku app.
My Procfile reads:
web: java $JAVA_OPTS -Ddw.server.connector.port=$PORT -Ddw.database.url=$DATABASE_URL -jar target/api-1.0-SNAPSHOT.jar server config.yml
When I try to deploy I receive the following error/crash message in the logs.
org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator: HHH000342: Could not obtain connection to query metadata : Driver:org.postgresql.Driver#53d13cd4 returned null for URL:postgres://fdeqzbddzbefaz:138912590e989b1b8fab5d169a1aea291f04b2d3bc040b1bbf6642a9207a5355#ec2-54-235-101-91.compute-1.amazonaws.com:5432/d67crr4pvqrfee
Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
State changed from starting to crashed
Process exited with status 1
My config.yml reads
database:
# the name of your JDBC driver
driverClass: org.postgresql.Driver
# the username
user: localusername
# the JDBC URL
url: jdbc:postgresql://localhost/dbname
# use the simple server factory if you only want to run on a single port
# HEROKU NOTE - the port gets be overridden with the Heroku $PORT in the Procfile
server:
type: simple
applicationContextPath: /
#adminContextPath: /admin # If you plan to use an admin path, you'll need to also use non-root app path
connector:
type: http
port: 8080
Does anyone have any trouble shooting ideas?
The DATABASE_URL env var is not directly compatible with the JDBC URL format. See docs. Specifically,
The DATABASE_URL for the Heroku Postgres add-on follows the below convention
postgres://username:password#host:port/dbname
However the Postgres JDBC driver uses the following convention:
jdbc:postgresql://host:port/dbname?user=username&password=password
Instead, try using JDBC_DATABASE_URL as documented here

Install rails with WSL and postgresql

I'm trying to setup a rails environment development on a Windows 10.
I follow the tutorial of 'go_rails' (https://gorails.com/setup/windows/10)
Most of the installation seems to worked fine (when i type rby -v or rails -v in the bash it's return the expected result).
My issue is with postresql which is used for the project i work on it.
Following the instructions of the tutorial i install Postgresql (10) directly on Windows. It's seems to work since in can login using the pgadmin on windows or by typing 'psql -p 5432 -h localhost -U postgres' in the bash.
So it's look like postgresql is working, but when i do a rake db:create in bash, i got an error : could not connect to the server: No such file or directory. Is the server running locally and accepting connections on Unix domain socket '/var/run/postgresql/.s.PGSQL.5432'
In the postgresql.conf (C:/Programms/.../Data/postgresql.conf) the listen_addresses is set to '*'.
A bit after there is a line named '#unix_socket_directoris = ''', do you thing i should set something in there?
I really need to get that project work.
Thanks for your help
The problem is likely that you've installed the Windows binary for PostgreSQL, but you're trying to connect to it from Windows Subsystem for Linux using a Unix socket, which doesn't exist.
You need to use TCP/IP to connect rather than a Unix socket. When typing psql on the command line, add the option --host=127.0.0.1 to connect via TCP/IP.
I just went through the entire Go Rails tutorial and I also had trouble at the rake db:create step. All you need to do is add host: 127.0.0.1 to your database.yml as shown below. Make sure to Start PostgreSQL before you run rake db:create.
default: &default
host: 127.0.0.1
adapter: postgresql
encoding: unicode
username: postgres
password: ENV['POSTGRESQL_PASSWORD']
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
development:
<<: *default
database: app_development
test:
<<: *default
database: app_test
production:
<<: *default
database: app_production
username: app_username
password: <%= ENV['APP_DATABASE_PASSWORD'] %>
Add host: localhost to your default: in database.yml. Without something telling rails where to look for the host, it looks for the process in linux, which, of course, won't work, since windows processes are not exposed to the wsl layer.

Unable to get MariaDB 10.1 (on centos 7) to listen only on IPv4

How could I get MariaDB 10.1 to listen only on IPv4? Strange but true the very first time I installed MariaDB and started it, I saw that it was correctly listening on IPv4 as shown in the example picture below
But strangely after reinstalling MariaDB for some reasons and rebooting my Centos 7 installation, it seems to have started listening only on IPv6 and I hence I cannot get the Galera Cluster to work (which was working fine when it was listening on IPv4). So how do I get this MariaDB to listen only on IPv4. The below is a screenshot from my machine
[root#dataqry-0001 ~]# netstat -ntpl | grep sql
tcp6 0 0 :::3306 :::* LISTEN 14323/mysqld
Contents of /etc/my.cnf.d/server.cnf (Pls note that I also tried uncommenting out the bind address, it is still the same strangely)
#
# These groups are read by MariaDB server.
# Use it for options that only the server (but not clients) should see
#
# See the examples of server my.cnf files in /usr/share/mysql/
#
# this is read by the standalone daemon and embedded servers
[server]
# this is only for the mysqld standalone daemon
[mysqld]
#
# * Galera-related settings
#
[galera]
# Mandatory settings
#wsrep_on=ON
#wsrep_provider=
#wsrep_cluster_address=
#binlog_format=row
#default_storage_engine=InnoDB
#innodb_autoinc_lock_mode=2
#
# Allow server to accept connections on all interfaces.
#
#bind-address=0.0.0.0
#
# Optional setting
#wsrep_slave_threads=1
#innodb_flush_log_at_trx_commit=0
# this is only for embedded server
[embedded]
# This group is only read by MariaDB servers, not by MySQL.
# If you use the same .cnf file for MySQL and MariaDB,
# you can put MariaDB-only options here
[mariadb]
# This group is only read by MariaDB-10.1 servers.
# If you use the same .cnf file for MariaDB of different versions,
# use this group for options that older servers don't understand
[mariadb-10.1]
I should add that I am quite confused with MariaDB / MySQL settings littered all over the place. The above bind-address is for Galera I guess. It's my first time with MariaDB on Centos 7, so apologies - I even tried disabling IPv6 earlier but doesn't show it listening on IPv4
Thanks
M.M
Preface
Although the information in the official MariaDB bug-tracker seems to suggest that this is not possible, unless the mysql software is used instead; I can confirm that setting the following configuration option in e.g. /etc/my.cnf, at least while using version 10.1.21-MariaDB, does work as expected and as outlined in #Hackerman's comment.
bind-address=0.0.0.0
The misunderstood/misleading/irrelevant official bug-trackers I eluded to:
MDEV-6536 (Open)
MDEV-4379 (Closed)
Answer
To answer the question as it pertains to your specific scenario, however, you should pay attention to the "section" under which that setting is set; namely, you have it written under the [galera] section, rather than the server-wide [mysqld] section.
[mysqld]
#
# * Galera-related settings
#
[galera]
# Mandatory settings
#wsrep_on=ON
#wsrep_provider=
#wsrep_cluster_address=
#binlog_format=row
#default_storage_engine=InnoDB
#innodb_autoinc_lock_mode=2
#
# Allow server to accept connections on all interfaces.
#
#bind-address=0.0.0.0
Make sure bind-address is specified in the [mysqld] section.

Rails app behaving differently in development vs production

Can someone please shed some light on why the app is behaving differently in production vs development mode. I have checked and re-checked config/database.yml and ensured that the username and password are correct. In fact as of writing this I have set both, development and production database to be same. Yet, when I run the server in production environment, Mysql2 complains about access denied, but works fine in development environment.
Same thing happens when running rails c production vs rails c development , no error in development but Mysql2 access denied in production.
Production mode
$ rails s -e production
=> Booting WEBrick
=> Rails 4.0.2 application starting in production on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2014-03-19 18:20:22] INFO WEBrick 1.3.1
[2014-03-19 18:20:22] INFO ruby 2.1.0 (2013-12-25) [x86_64-freebsd10.0]
[2014-03-19 18:20:22] INFO WEBrick::HTTPServer#start: pid=10800 port=3000
I, [2014-03-19T18:20:30.569167 #10800] INFO -- : Started GET "/" for 192.168.1.102 at 2014-03-19 18:20:30 +0200
F, [2014-03-19T18:20:30.709229 #10800] FATAL -- :
Mysql2::Error (Access denied for user 'root'#'localhost' (using password: YES)):
Development Mode
$ rails s -e development
=> Booting WEBrick
=> Rails 4.0.2 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2014-03-19 18:22:53] INFO WEBrick 1.3.1
[2014-03-19 18:22:53] INFO ruby 2.1.0 (2013-12-25) [x86_64-freebsd10.0]
[2014-03-19 18:22:53] INFO WEBrick::HTTPServer#start: pid=10898 port=3000
Started GET "/" for 192.168.1.102 at 2014-03-19 18:23:03 +0200
Processing by Rails::WelcomeController#index as HTML
Rendered /home/user/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.0.2/lib/rails/templates/rails/welcome/index.html.erb (2.3ms)
Completed 200 OK in 24ms (Views: 11.6ms | ActiveRecord: 0.0ms)
And here is my config/database.yml.
development:
adapter: mysql2
encoding: utf8
database: amo
pool: 5
username: root
password: mypass
host: localhost
production:
adapter: mysql2
encoding: utf8
database: amo
pool: 5
username: root
password: mypass
host: localhost
O/S : FreeBSD 10.0 64bit
Ruby : 2.1.0 (installed using Rbenv)
Rails : 4.0.2
A common problem is that the DB user permissions are setup with % to refer to local access permissions....
...but in the prod environment, where the DB and web servers are on different machines, you need to set the user permission to come from the IP, DNS, etc of the web server machine.
For instance, you may have perms like this:
grant all privileges on mydb.* to myuser#'%' identified by 'mypasswd';
grant all privileges on mydb.* to myuser#localhost identified by 'mypasswd';
But this will only work for your local dev environment. You may have this kind of permission setup scripted, in which case you'd need different setup perms for your prod DB.
In the prod environment, you may have your web service on 168.0.1.2 and your DB on 168.0.1.100. So your prod DB would need:
grant all privileges on mydb.* to myuser#168.0.1.2 identified by 'mypasswd';
If you add another web server, remember to add permissions for users coming from that machine.
If none of this is ringing a bell, post your GRANTS (change the private details). I'll dig out the commands to do this, if you aren't familiar.

First ruby and postgreSql application - getting could not connect to server: No such file or directory

Ruby 1.9.3 on Mac OS X Lion
Followed several posts on SO about this topic. Neither helped.
Trying to run my first rails and postgreSQL app here.
Following this:
http://guides.rubyonrails.org/getting_started.html
When I do:
"rake db:create"
I get:
could not connect to server: No such file or directory Is the server
running locally and accepting connections on Unix domain socket
"/tmp/.s.PGSQL.5432"?
Some facts:
Not sure what /tmp/ is it referring to but, if it is the one from root, then:
1)
Permissions:
drwxrwxrwx 11 root wheel 374B Jan 4 17:33 tmp
2)
Also, I see no file .s.PGSQL.5432.
3)
I've tried to force the socket location by adding to database.yml the following:
development:
adapter: postgresql
encoding: unicode
database: testblog_development
pool: 5
username: blog
password:
socket: /var/pgsql_socket # <-- this line
(it stills shows me the same error with the /tmp/ path).
4) When I do, which postgres I get:
/usr/local/bin/postgres
(I've used homebrew installation)
5) When I do: brew info postgres I get:
postgresql: stable 9.2.2 http://www.postgresql.org/ Depends on:
readline, ossp-uuid Conflicts with: postgres-xc
/usr/local/Cellar/postgresql/9.2.2 (2819 files, 39M) *
https://github.com/mxcl/homebrew/commits/master/Library/Formula/postgresql.rb
and other bunch of information.
That seems to me like the server isn't running. Do you see anything when you run ps aux | grep postgres from the command line? If all you see is something along the lines of grep postgres in the output, it's not running.
Since you installed PostgreSQL with Homebrew, try brew info postgres for information on how to start up the server if that is indeed the case.
You don't need to specify a socket. Here's a configuration that works for Postgres. You only need to change the database password.
development:
adapter: postgresql
host: localhost
pool: 5
timeout: 5000
username: postgres
password: postgres
database: testblog_development
template: template0

Resources