I am running this on centos 6.6
PSQL='/usr/bin/psql'
su - postgres "$PSQL" template1 -f 'sql.sql'
But starting psql always fails to start
Starting postgresql-9.4 service: [FAILED]
and then I get this error
/usr/bin/psql: /usr/bin/psql: cannot execute binary file
Thank you for all the help.
Try this:
PSQL='/usr/bin/psql'
su - postgres -c "$PSQL template1 -f 'sql.sql'"
Related
I spent more than two days on this and I ran out of ideas and I really hope someone here will be able to help.
I am running docker on my Linux Fedora laptop.
[julian#julian-hp ~]$ docker -v
Docker version 18.06.1-ce, build e68fc7a
I loaded an oracle 12c image from another laptop (running Linux Ubuntu) and ran it using the following command:
docker run --name oracle_12c_201 -p 1521:1521 -p 5500:5500
-v /opt/dev/data/oracle/o12c_201_u02/:/opt/oracle/oradata
-e ORACLE_PWD=admin 12a359cd0528
The container gets created and is displayed as healthy when running docker ps:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
544917a88b6b 12a359cd0528 "/bin/sh -c '/bin/ba…" 2 days ago Up 2 days (healthy) 0.0.0.0:1521->1521/tcp, 0.0.0.0:5500->5500/tcp oracle_12c_201
However when I try to login to my running instance I am getting ORA-01017: Invalid username/password; logon denied message
All of the HOW TOs I found on the internet say that if you do not specify a password when you create the container using docker run the the SYS password will be displayed under this line:
ORACLE PASSWORD FOR SYS, SYSTEM AND PDBADMIN:
There is not such a line in my logs. Note I deleted the container using all possible permutations such following internet articles such as -e "ORACLE_PWD=admin" or not specifying a password at running docker run using sudo nothing worked.
When trying to change the password using below:
docker exec oracle_12c_201 ./setPassword.sh admin
It fails with the following error mesage:
OCI runtime exec failed: exec failed: container_linux.go:348: starting container
process caused "exec: \"./setPassword.sh\": stat ./setPassword.sh:
no such file or directory": unknown
I ran out of ideas. I can see from the logs that the database is up and running but it is useless as long as I cannot connect to it. Note that the same image runs OK and I can connect to it without any problems on my other laptop running Linux Ubuntu. Unfortunately I no longer have the commands that I used to install oracle on that machine.
Thank you in advance for your help.
How can I set Postgres in Travis CI OS X build?
I can't start and I don't know how to set these:
--dbaddress localhost --dbport 5432 --dbname testDb --dbusername postgres
With the Travis CI OS X instances the environment is similar to a typical Homebrew installation.
Here is the Travis CI OS X environment you can configure.
The database services that are available:
postgis version 2.1.3, postgresql version 9.3.5
Unlike Linux, the service configuration is not currently available in OSX. You start a database service using the install script and making use of the Postgresql tools directly.
An example .travis.yml looks like this:
addons:
postgresql: "9.4"
language:
- objective-c
os:
- osx
sudo:
- false
install:
- export PG_DATA=$(brew --prefix)/var/postgres
- pg_ctl -w start -l postgres.log --pgdata ${PG_DATA}
- createuser -s postgres
- psql -c 'create database testDb;' -U postgres
- cat postgres.log
So what does it do?
“add ons” is selecting your specific postgresql version over the default
“sudo” commands cannot be executed in Travis CI
“install” contains the commands we need to run and others you want to add
The pg_ctl command requires a data directory, “PG_DATA” contains a path to the local home-brew installation and your directory to store database files.
pg_ctl will start the existing service and wait(-w) to be connected.
A unix user/role "postgres" must be created and is used in the final creation script for your database “testDb”.
Finally, the postgres.log is sent to Travis CI log.
Hopefully, that gives you an idea of where to start.
Additional information to griffio's answer:
In the meantime Travis is running PostgreSQL 9.5 (even with addon postgresql: "9.4") and I got the following log output when starting:
FATAL: database files are incompatible with server
DETAIL: The data directory was initialized by PostgreSQL version 9.4, which is not compatible with this version 9.5.4.
It's working after creating a new cluster first:
install:
- export PG_DATA=$(brew --prefix)/var/postgres
- rm -rf $PG_DATA
- initdb $PG_DATA -E utf8
- pg_ctl -w start -l postgres.log --pgdata ${PG_DATA}
- createuser -s postgres
- psql -c 'create database testDb;' -U postgres
I'm working on a bash script for automatic MongoDB server installation and user creation.
#!/bin/bash
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | tee /etc/apt/sources.list.d/mongodb.list
apt-get update
apt-get install -y mongodb-org
update-rc.d mongod defaults
sed -i 's/^auth = true/#auth = true/g' /etc/mongod.conf
sed -i 's/^#noauth = true/noauth = true/g' /etc/mongod.conf
service mongod restart
mongo user_creation.js
The script is run on a clean precise64 Vagrant VM. Add the Debian/Ubuntu repo to install the latest version (we're on Ubuntu 12.04 LTS, the maintained version is 2.0.X), add server to startup, set some variables in the MongoDB config file. Simple stuff really, however, the last line fails each and every time.
MongoDB shell version: 2.6.4 connecting to: test 2014-10-03T12:34.:56.000+0000
warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2014-10-03T12:34.:56.000+0000 Error: couldn't connect to server 127.0.0.1:27017
(127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146
exception: connect failed
I thought maybe the server needed some time to load data or some other kind of initialization between its restart and the client connection so I tried putting a sleep 30 between the last two instructions : didn't work. However, removing the mongo execution from the script and starting it manually works like a charm every time! The .js is not the problem here, I've tested it and it's working alright.
Does anyone have any idea why the mongo cannot connect on its first try and how I could fix this? For now, I'll settle with this terrible (working) hack, but I'd rather have a cleaner, hackless script:
while :
do
RESULT=`mongo --eval "1;"`
echo $RESULT
if [[ "${RESULT:-null}" == *Failed\ to\ connect* ]]
then
sleep 1
else
mongo root_creation.js
break;
fi
done
It's ugly but after 1 to 10 tries, it ends up connecting and working perfectly.
I'm completely new to databases and am trying to set up mongodb.
I've followed all the steps but neither the mongod or mongo commands work.
This is the output from mongod:
ERROR: could not read from config file
That is followed by all the mongo options (-h, -f, -v, etc.)
This is the output from mongo:
MongoDB shell version: 2.4.6
connecting to: test
Fri Sep 6 22:55:35.889 Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:145
exception: connect failed
Any help is appreciated!
Try starting mongod with --config option specified. Something like /path/to/mongod --config /path/to/mongodb.conf.
In your mongodb.config check the location to the mongodb log. You should find additional details about errors there. Possible problems are: db path does not exist or is not writable, after an unclean shutdown mongod.lock file still exists etc.
I followed the instructions for setting up postgresql from this site
All seems to go fine until I try:
createuser --superuser myname -U
postgres
I get the following exception:
createuser: could not connect to
database postgres: 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"?
For the life of me I can't figure out how to resolve this. Any ideas???
I had to remove the existing postgres user before doing the install.
Perhaps you moved your postgres data directory after you installed postgres using macports
Find where your launchctl startup script is located.
ps -ef | grep postgres
Outputs
0 54 1 0 0:00.01 ?? 0:00.01 /opt/local/bin/daemondo --label=postgresql84-server --start-cmd /opt/local/etc/LaunchDaemons/org.macports.postgresql84-server/postgresql84-server.wrapper start ; --stop-cmd /opt/local/etc/LaunchDaemons/org.macports.postgresql84-server/postgresql84-server.wrapper stop ; --restart-cmd /opt/local/etc/LaunchDaemons/org.macports.postgresql84-server/postgresql84-server.wrapper restart ; --pid=none
So I edit
sudo vim /opt/local/etc/LaunchDaemons/org.macports.postgresql84-server/postgresql84-server.wrapper
And find the line
Start() {
su postgres -c "${PGCTL} -D ${POSTGRESQL84DATA:=/opt/local/var/db/postgresql84/wrong_place} start -l /opt/local/var/log/postgresql84/postgres.log"
}
Ahh.. my data directory is in the wrong place. I fix it by changing
/opt/local/var/db/postgresql84/wrong_place
to
/opt/local/var/db/postgresql84/right_place
for both the start and stop command.
Did you install the postgresql84-server port? If so, did you start the server:
$ sudo port load postgresql84-server
If you did both of those, I've noticed that sometimes the MacPorts daemon handler (daemondo) doesn't start handling requests for PostgreSQL until you restart your machine. (This only happens the first time it is started; subsequent attempts should work fine.)