I restarted my computer recently and after trying to start my db locally with rails s I got the following:
/Users/example_name/.rvm/gems/ruby-1.9.3-p374/gems/activerecord-3.2.11/lib/active_record/connection_adapters/postgresql_adapter.rb:1208:in
`initialize': could not connect to server:
No such file or directory (PGError)
Then I tried to manually start the db by writing:
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
And then it said server starting So I retyped rails s and then I recieved the error:
FATAL: role example_name doesn't exist
Which was a strange error I never got before so I tried to create the role again and after running rails s again I then got:
FATAL: database "example_db" does not exist (PGError)
I don't think I did anything to drop the db so I'm unsure what exactly is going on.
I did rake db:create:all and bundle exec rake db:migrate and now it works but the DB is empty! how did this happen? this isn't going to empty my production db if I deploy will it?
Related
I keep a sql import file that I regularly use to build a site, and after upgrading to ddev v0.19.0, I get this when I do `ddev import-db --src=.tarballs/d7git.sql.gz:
Failed to import database for d7git: Failed to run docker-compose [-f /Users/rfay/workspace/d7git/.ddev/docker-compose.yaml exec -T db bash -c mysql --database=mysql -e 'DROP DATABASE IF EXISTS db; CREATE DATABASE db;' && cat /db/*.*sql | mysql db], err='exit status 1', stdout='', stderr='ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)'
This is a result of a bug fix in the mariadb container. Unfortunately it introduces this problem for you.
Fix it by removing the database entirely and restarting:
ddev delete --omit-snapshot
ddev start
ddev import-db --src=<yourdb>
What's happening is that we're now importing the database using higher (root) privileges to solve a few problems people had. But in v0.18.0, the root user was broken. So if you just remove the whole database and start from scratch, everything works fine (and lots of things that didn't work before too). This is a one-time-per-project fix and you should be able to import without doing this in the future.
I had a Rails project on C9 with a SQLite 3 database. Recently I wanted to switch to a PostgreSQL database to be able to run a project on Heroku. All records from the SQLite 3 database were copied to the PostgreSQL database with the Sequel gem, without any issues. All records were passed to the new database and I was able to see it, however, after rebooting my C9 project, and starting the PostgreSQL service, and connecting it to my database, I found that there weren't any records inside the database. Or, it's not connected yet. I don't get it.
Every time I reboot the project, records from the PostgreSQL database disappear, I have to create a new database and migrate it again to see my records. What am I doing wrong?
Here is list of my actions:
sudo service postgresql start
psql -c "create database myapp_development owner=ubuntu"
sequel -C sqlite://db/development.sqlite3 postgres://ubuntu#""/myapp_development
Then update database.yml file records with:
Development:
- adapter: postgresql
- encoding: SQL_ASCII
- database: myapp_development
- pool: 5
- username: ubuntu
- password: password
Then run:
rake db:migrate
After these actions I can run the project and see my records.
After rebooting the project, I've tried to run the following commands:
sudo service postgresql start
psql myapp_development ubuntu
\c
but it does not help me to see any records.
Please advise me if I've missed any command.
Run psql as the postgres user:
sudo sudo -u postgres psql -d myapp_development -U ubuntu -W
Please, I need help with my postgres server. I have problems starting the server. I was using the app here a few months ago and everything was fine. Today I spent hours trying to start it yet couldn't. I then realised I had another instance of PostgreSQL installed. I uninstalled version 9.6 blocking my app.
Now after trying again, the PostgreSQL app throws the error when I use psql:
FATAL: role "username" does not exist
I didn't set the role or user but it somehow took my username and is throwing does not exist. Please, how do I start my server. I have seen someone with a similar issue here but unlike in his case, I didn't even get to start the server. not to speak of deleting the database. Please, how do I address this? Any help would be appreciated.
I also noticed he was able to execute
which psql
which returned his supposed psql path. It does not return anything in my case. Not sure how the configuration works, this is my second time using this database and it failed right away.
Thank you for your time, as answered in one of the SO question here. Running
sudo -u postgres -i
did give me access to postgres, but if you are using the postgres app like myself here . Running psql commands would not work for you as postgres is not installed globally on your machine. But running
'/Applications/Postgres.app/Contents/Versions/9.5/bin'/psql -p5432
which is the exact command the postgres app execute when you attempt to start the service works great and start the service for me. You can then proceed and add the role and database your postgres app looks for by default. So in summary. Below is what worked for me.
$sudo -u postgres -i
$'/Applications/Postgres.app/Contents/Versions/9.*/bin'/psql -p5432
#CREATE USER postgres SUPERUSER;
#CREATE DATABASE postgres WITH OWNER postgres;
I just updated my mac OS X to Yosemite, version 10.10.4, and postgresql to: psql (PostgreSQL) 9.4.4.
After running rake db:migrate on my Rails 4.2.1 application, my terminal session is responding with:
rake aborted!
PG::ConnectionBad: could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
Simply entering psql in my terminal session also appears a bit off:
$ psql
psql: 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"?
After printing out the logs from, cat /usr/local/var/postgres/server.log, I read:
DETAIL: The data directory was initialized by PostgreSQL version 9.3, which is not compatible with this version 9.4.4.
LOG: skipping missing configuration file "/usr/local/var/postgres/postgresql.auto.conf"
FATAL: database files are incompatible with server
I found this answer on SO, but I a hesitant to just start creating a bunch of directories unless that's really what I am suppose to do. I also found an older answer but am not too sure if it's the one to follow.
This SO answer suggests that I remove a, /usr/local/var/postgres/postmaster.pid, but I do not have one, I have a, /usr/local/var/postgres/postmaster.opts -- should I remove the postmaster.opts?
There appears to be lots of advice, but I am not too sure what to follow. Can someone offer some advice in getting my postgresql database running on my rails application?
You could upgrade the database by following an official guide:
brew switch postgres 9.3 # presuming you already installed 9.4.4
pg_dumpall > outputfile
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
mv /usr/local/var/postgres /usr/local/var/postgres.old
brew switch postgres 9.4.4
initdb -D /usr/local/var/postgres
psql -d postgres -f outputfile
PostgreSQL upgrade
Basically, I had to drop and recreate my own database and re-seed it with remote staging data. What I did not understand is that the problem with updating a database is that the data itself also needs to be 'updated' in a way. The data was compatible with a different version
The error in its entirety reads:
psql: 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"?
This is my second time setting up Postgresql via Homebrew on my Mac, and I have no clue what is going on. Previously, it had been working. At some point, I must've entered a command that messed things up. I'm not sure. Now, whenever I enter a SQL command from the command line, I receive the above message. I've run a command to check whether the server is running, and it apparently is not. If I attempt to start the server using
$ postgres -D /usr/local/pgsql/data
I receive the following error:
postgres cannot access the server configuration file
"/usr/local/pgsql/data/postgresql.conf": No such file or directory
I've uninstalled and reinstalled Postgresql via Homebrew, but the problem persists. I'm completely at a loss as to how to get this working. Any help would be appreciated.
your data directory is most likely wrong.
issue a "sudo find / -name "postgresql.conf" " on your terminal to see where your postgres file resides. Then, do an ls in the data directory. Use that in the -D option when starting postgres.