How to log into the database under the user? - psql

I install postres9 on linux mint 18. I login under default postres user. I try create new user and login under this user.
kalinin#lenovo ~ $ sudo -i -u postgres
postgres#lenovo ~ $ psql
psql (9.5.16)
Type "help" for help.
postgres=# CREATE DATABASE db_test;
CREATE DATABASE
postgres=# CREATE USER user_test WITH PASSWORD 'qwerty';
CREATE ROLE
postgres=#
postgres=#
postgres=# GRANT ALL PRIVILEGES ON DATABASE "db_test" to user_test;
GRANT
postgres=# \du
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------------------+-----------
postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
user_test | | {}
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-------------+----------+----------+-------------+-------------+------------------------
db_test | postgres | UTF8 | ru_RU.UTF-8 | ru_RU.UTF-8 | =Tc/postgres +
| | | | | postgres=CTc/postgres +
| | | | | user_test=CTc/postgres
postgres | postgres | UTF8 | ru_RU.UTF-8 | ru_RU.UTF-8 |
postgres=# \q
postgres#lenovo ~ $ exit
logout
kalinin#lenovo ~ $ sudo -i -u user_test
sudo: unknown user: user_test
sudo: unable to initialize policy plugin
you see what i am creating new user with password and new database. after that i exit from postgres and try login again. But login failed. Please help fix it.

Related

how to retrieve value of 'Position' from SHOW MASTER STATUS in mariadb

How can I retrieve just the 'position' value from the 'SHOW MASTER STATUS' query expression in MariaDB(running in docker container) from outside the docker container ?
Something like, I have the following :-
+-------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+-------------------+----------+--------------+------------------+
| master-bin.000003 | 375 | | |
+-------------------+----------+--------------+------------------+
and need to get only value of position using bash script ?
Please help as soon as possible.
When MariaDB running inside docker container and want to retrieve File and Position Value from "SHOW MASTER STATUS" in MariaDB/MySQL from outside the docker container, use the following command in bash :-
for File
docker exec -it <mariadb_container_name> bash -c "mysql -u<username> -p<password> -Ne 'show master status' | awk '{print $1}' | cut -f1"
for Position
docker exec -it <mariadb_container_name> bash -c "mysql -u<username> -p<password> -Ne 'show master status' | awk '{print $2}' | cut -f2"

Docker execute Deluge as a Swarm service

I am new to Docker and I want to run Deluge as a Swarm service
I am running Docker inside OSX
First I started up Swarm
$ docker swarm init
Then I created an overlay network, that then I would use on the service
$ docker network create --driver overlay p2pnetwork
After that I created the service for Swarm
$ docker service create --name deluge \
--network p2pnetwork \
--replicas 1 \
linuxserver/deluge \
-e PUID=501 -e PGID=20 \
-e TZ=ART \
-e UMASK_SET=022 \
-v /Users/agus/Downloads/torrents/incoming:/downloads \
-v /Users/agus/Downloads/torrents/config:/config \
-p 8112:80
Then when I collected this data
$ docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
0eydgjayj3q8 deluge replicated 0/1 linuxserver/deluge:latest
$ docker service ps deluge
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
xdut1h8riw56 deluge.1 linuxserver/deluge:latest moby Running Starting 1 second ago
8c54vkti22c8 \_ deluge.1 linuxserver/deluge:latest moby Shutdown Failed 6 seconds ago "task: non-zero exit (111)"
3oan0xb349zi \_ deluge.1 linuxserver/deluge:latest moby Shutdown Failed 17 seconds ago "task: non-zero exit (111)"
xvri5grnmi4g \_ deluge.1 linuxserver/deluge:latest moby Shutdown Failed 27 seconds ago "task: non-zero exit (111)"
9rcmvxihyg91 \_ deluge.1 linuxserver/deluge:latest moby Shutdown Failed 39 seconds ago "task: non-zero exit (111)"
$ docker service logs deluge
deluge.1.xvri5grnmi4g#moby | [s6-init] making user provided files available at /var/run/s6/etc...exited 0.
deluge.1.xdut1h8riw56#moby | [s6-init] making user provided files available at /var/run/s6/etc...exited 0.
deluge.1.xvri5grnmi4g#moby | [s6-init] ensuring user provided files have correct perms...exited 0.
deluge.1.3oan0xb349zi#moby | [s6-init] making user provided files available at /var/run/s6/etc...exited 0.
deluge.1.xvri5grnmi4g#moby | [fix-attrs.d] applying ownership & permissions fixes...
deluge.1.xdut1h8riw56#moby | [s6-init] ensuring user provided files have correct perms...exited 0.
deluge.1.8c54vkti22c8#moby | [s6-init] making user provided files available at /var/run/s6/etc...exited 0.
deluge.1.8c54vkti22c8#moby | [s6-init] ensuring user provided files have correct perms...exited 0.
deluge.1.3oan0xb349zi#moby | [s6-init] ensuring user provided files have correct perms...exited 0.
deluge.1.xvri5grnmi4g#moby | [fix-attrs.d] done.
deluge.1.xdut1h8riw56#moby | [fix-attrs.d] applying ownership & permissions fixes...
deluge.1.xdut1h8riw56#moby | [fix-attrs.d] done.
deluge.1.8c54vkti22c8#moby | [fix-attrs.d] applying ownership & permissions fixes...
deluge.1.3oan0xb349zi#moby | [fix-attrs.d] applying ownership & permissions fixes...
deluge.1.xvri5grnmi4g#moby | [cont-init.d] executing container initialization scripts...
deluge.1.xvri5grnmi4g#moby | [cont-init.d] 10-adduser: executing...
deluge.1.xdut1h8riw56#moby | [cont-init.d] executing container initialization scripts...
deluge.1.8c54vkti22c8#moby | [fix-attrs.d] done.
deluge.1.3oan0xb349zi#moby | [fix-attrs.d] done.
deluge.1.3oan0xb349zi#moby | [cont-init.d] executing container initialization scripts...
deluge.1.xvri5grnmi4g#moby | usermod: no changes
deluge.1.xdut1h8riw56#moby | [cont-init.d] 10-adduser: executing...
deluge.1.8c54vkti22c8#moby | [cont-init.d] executing container initialization scripts...
deluge.1.8c54vkti22c8#moby | [cont-init.d] 10-adduser: executing...
deluge.1.3oan0xb349zi#moby | [cont-init.d] 10-adduser: executing...
deluge.1.xvri5grnmi4g#moby |
deluge.1.xdut1h8riw56#moby | usermod: no changes
deluge.1.xdut1h8riw56#moby |
deluge.1.8c54vkti22c8#moby | usermod: no changes
deluge.1.3oan0xb349zi#moby | usermod: no changes
deluge.1.xvri5grnmi4g#moby | -------------------------------------
deluge.1.xvri5grnmi4g#moby | _ _ _
deluge.1.xdut1h8riw56#moby | -------------------------------------
deluge.1.8c54vkti22c8#moby |
deluge.1.3oan0xb349zi#moby |
deluge.1.3oan0xb349zi#moby | -------------------------------------
deluge.1.xvri5grnmi4g#moby | | |___| (_) ___
deluge.1.xdut1h8riw56#moby | _ _ _
deluge.1.8c54vkti22c8#moby | -------------------------------------
deluge.1.8c54vkti22c8#moby | _ _ _
deluge.1.xvri5grnmi4g#moby | | / __| | |/ _ \
deluge.1.3oan0xb349zi#moby | _ _ _
deluge.1.xdut1h8riw56#moby | | |___| (_) ___
deluge.1.xvri5grnmi4g#moby | | \__ \ | | (_) |
deluge.1.8c54vkti22c8#moby | | |___| (_) ___
deluge.1.3oan0xb349zi#moby | | |___| (_) ___
deluge.1.xdut1h8riw56#moby | | / __| | |/ _ \
deluge.1.8c54vkti22c8#moby | | / __| | |/ _ \
deluge.1.xdut1h8riw56#moby | | \__ \ | | (_) |
deluge.1.3oan0xb349zi#moby | | / __| | |/ _ \
deluge.1.xvri5grnmi4g#moby | |_|___/ |_|\___/
deluge.1.xvri5grnmi4g#moby | |_|
deluge.1.8c54vkti22c8#moby | | \__ \ | | (_) |
deluge.1.xdut1h8riw56#moby | |_|___/ |_|\___/
deluge.1.3oan0xb349zi#moby | | \__ \ | | (_) |
deluge.1.3oan0xb349zi#moby | |_|___/ |_|\___/
deluge.1.xvri5grnmi4g#moby |
deluge.1.8c54vkti22c8#moby | |_|___/ |_|\___/
deluge.1.xdut1h8riw56#moby | |_|
deluge.1.3oan0xb349zi#moby | |_|
deluge.1.8c54vkti22c8#moby | |_|
deluge.1.xvri5grnmi4g#moby | Brought to you by linuxserver.io
deluge.1.xvri5grnmi4g#moby | We gratefully accept donations at:
deluge.1.3oan0xb349zi#moby |
deluge.1.xdut1h8riw56#moby |
deluge.1.8c54vkti22c8#moby |
deluge.1.8c54vkti22c8#moby | Brought to you by linuxserver.io
deluge.1.xvri5grnmi4g#moby | https://www.linuxserver.io/donations/
deluge.1.3oan0xb349zi#moby | Brought to you by linuxserver.io
deluge.1.xdut1h8riw56#moby | Brought to you by linuxserver.io
deluge.1.3oan0xb349zi#moby | We gratefully accept donations at:
deluge.1.8c54vkti22c8#moby | We gratefully accept donations at:
deluge.1.xvri5grnmi4g#moby | -------------------------------------
deluge.1.xvri5grnmi4g#moby | GID/UID
deluge.1.xdut1h8riw56#moby | We gratefully accept donations at:
deluge.1.3oan0xb349zi#moby | https://www.linuxserver.io/donations/
deluge.1.8c54vkti22c8#moby | https://www.linuxserver.io/donations/
deluge.1.8c54vkti22c8#moby | -------------------------------------
deluge.1.xvri5grnmi4g#moby | -------------------------------------
deluge.1.xdut1h8riw56#moby | https://www.linuxserver.io/donations/
deluge.1.3oan0xb349zi#moby | -------------------------------------
deluge.1.3oan0xb349zi#moby | GID/UID
deluge.1.8c54vkti22c8#moby | GID/UID
deluge.1.xvri5grnmi4g#moby | User uid: 911
deluge.1.xdut1h8riw56#moby | -------------------------------------
deluge.1.xdut1h8riw56#moby | GID/UID
deluge.1.3oan0xb349zi#moby | -------------------------------------
deluge.1.8c54vkti22c8#moby | -------------------------------------
deluge.1.xvri5grnmi4g#moby | User gid: 911
deluge.1.3oan0xb349zi#moby | User uid: 911
deluge.1.xdut1h8riw56#moby | -------------------------------------
deluge.1.xvri5grnmi4g#moby | -------------------------------------
deluge.1.8c54vkti22c8#moby | User uid: 911
deluge.1.8c54vkti22c8#moby | User gid: 911
deluge.1.3oan0xb349zi#moby | User gid: 911
deluge.1.xdut1h8riw56#moby | User uid: 911
deluge.1.xvri5grnmi4g#moby |
deluge.1.xvri5grnmi4g#moby | [cont-init.d] 10-adduser: exited 0.
deluge.1.8c54vkti22c8#moby | -------------------------------------
deluge.1.3oan0xb349zi#moby | -------------------------------------
deluge.1.xdut1h8riw56#moby | User gid: 911
deluge.1.xdut1h8riw56#moby | -------------------------------------
deluge.1.8c54vkti22c8#moby |
deluge.1.xvri5grnmi4g#moby | [cont-init.d] 30-config: executing...
deluge.1.3oan0xb349zi#moby |
deluge.1.3oan0xb349zi#moby | [cont-init.d] 10-adduser: exited 0.
deluge.1.xdut1h8riw56#moby |
deluge.1.8c54vkti22c8#moby | [cont-init.d] 10-adduser: exited 0.
deluge.1.xvri5grnmi4g#moby | [cont-init.d] 30-config: exited 0.
deluge.1.xvri5grnmi4g#moby | [cont-init.d] done.
deluge.1.3oan0xb349zi#moby | [cont-init.d] 30-config: executing...
deluge.1.xdut1h8riw56#moby | [cont-init.d] 10-adduser: exited 0.
deluge.1.8c54vkti22c8#moby | [cont-init.d] 30-config: executing...
deluge.1.3oan0xb349zi#moby | [cont-init.d] 30-config: exited 0.
deluge.1.xvri5grnmi4g#moby | [services.d] starting services
deluge.1.8c54vkti22c8#moby | [cont-init.d] 30-config: exited 0.
deluge.1.xvri5grnmi4g#moby | [services.d] done.
deluge.1.xdut1h8riw56#moby | [cont-init.d] 30-config: executing...
deluge.1.3oan0xb349zi#moby | [cont-init.d] done.
deluge.1.3oan0xb349zi#moby | [services.d] starting services
deluge.1.8c54vkti22c8#moby | [cont-init.d] done.
deluge.1.xvri5grnmi4g#moby | exec: fatal: unable to exec -e: No such file or directory
deluge.1.xdut1h8riw56#moby | [cont-init.d] 30-config: exited 0.
deluge.1.8c54vkti22c8#moby | [services.d] starting services
deluge.1.3oan0xb349zi#moby | [services.d] done.
deluge.1.xdut1h8riw56#moby | [cont-init.d] done.
deluge.1.xvri5grnmi4g#moby | -e exited 111
deluge.1.8c54vkti22c8#moby | [services.d] done.
deluge.1.xvri5grnmi4g#moby | [cont-finish.d] executing container finish scripts...
deluge.1.3oan0xb349zi#moby | exec: fatal: unable to exec -e: No such file or directory
deluge.1.xdut1h8riw56#moby | [services.d] starting services
deluge.1.xdut1h8riw56#moby | [services.d] done.
deluge.1.8c54vkti22c8#moby | exec: fatal: unable to exec -e: No such file or directory
deluge.1.xvri5grnmi4g#moby | [cont-finish.d] done.
deluge.1.3oan0xb349zi#moby | -e exited 111
deluge.1.3oan0xb349zi#moby | [cont-finish.d] executing container finish scripts...
deluge.1.xdut1h8riw56#moby | exec: fatal: unable to exec -e: No such file or directory
deluge.1.8c54vkti22c8#moby | -e exited 111
deluge.1.xvri5grnmi4g#moby | [s6-finish] syncing disks.
deluge.1.xvri5grnmi4g#moby | [s6-finish] sending all processes the TERM signal.
deluge.1.xdut1h8riw56#moby | -e exited 111
deluge.1.3oan0xb349zi#moby | [cont-finish.d] done.
deluge.1.8c54vkti22c8#moby | [cont-finish.d] executing container finish scripts...
deluge.1.8c54vkti22c8#moby | [cont-finish.d] done.
deluge.1.xvri5grnmi4g#moby | [s6-finish] sending all processes the KILL signal and exiting.
deluge.1.xdut1h8riw56#moby | [cont-finish.d] executing container finish scripts...
deluge.1.3oan0xb349zi#moby | [s6-finish] syncing disks.
deluge.1.3oan0xb349zi#moby | [s6-finish] sending all processes the TERM signal.
deluge.1.8c54vkti22c8#moby | [s6-finish] syncing disks.
deluge.1.xdut1h8riw56#moby | [cont-finish.d] done.
deluge.1.xdut1h8riw56#moby | [s6-finish] syncing disks.
deluge.1.3oan0xb349zi#moby | [s6-finish] sending all processes the KILL signal and exiting.
deluge.1.8c54vkti22c8#moby | [s6-finish] sending all processes the TERM signal.
deluge.1.8c54vkti22c8#moby | [s6-finish] sending all processes the KILL signal and exiting.
deluge.1.xdut1h8riw56#moby | [s6-finish] sending all processes the TERM signal.
deluge.1.xdut1h8riw56#moby | [s6-finish] sending all processes the KILL signal and exiting.
deluge.1.m73zgk69hz2u#moby | [s6-init] making user provided files available at /var/run/s6/etc...exited 0.
deluge.1.m73zgk69hz2u#moby | [s6-init] ensuring user provided files have correct perms...exited 0.
deluge.1.m73zgk69hz2u#moby | [fix-attrs.d] applying ownership & permissions fixes...
deluge.1.m73zgk69hz2u#moby | [fix-attrs.d] done.
deluge.1.m73zgk69hz2u#moby | [cont-init.d] executing container initialization scripts...
deluge.1.m73zgk69hz2u#moby | [cont-init.d] 10-adduser: executing...
deluge.1.m73zgk69hz2u#moby | usermod: no changes
deluge.1.m73zgk69hz2u#moby |
deluge.1.m73zgk69hz2u#moby | -------------------------------------
deluge.1.m73zgk69hz2u#moby | _ _ _
deluge.1.m73zgk69hz2u#moby | | |___| (_) ___
deluge.1.m73zgk69hz2u#moby | | / __| | |/ _ \
deluge.1.m73zgk69hz2u#moby | | \__ \ | | (_) |
deluge.1.m73zgk69hz2u#moby | |_|___/ |_|\___/
deluge.1.m73zgk69hz2u#moby | |_|
deluge.1.m73zgk69hz2u#moby |
deluge.1.m73zgk69hz2u#moby | Brought to you by linuxserver.io
deluge.1.m73zgk69hz2u#moby | We gratefully accept donations at:
deluge.1.m73zgk69hz2u#moby | https://www.linuxserver.io/donations/
deluge.1.m73zgk69hz2u#moby | -------------------------------------
deluge.1.m73zgk69hz2u#moby | GID/UID
deluge.1.m73zgk69hz2u#moby | -------------------------------------
deluge.1.m73zgk69hz2u#moby | User uid: 911
deluge.1.m73zgk69hz2u#moby | User gid: 911
deluge.1.m73zgk69hz2u#moby | -------------------------------------
deluge.1.m73zgk69hz2u#moby |
deluge.1.m73zgk69hz2u#moby | [cont-init.d] 10-adduser: exited 0.
deluge.1.m73zgk69hz2u#moby | [cont-init.d] 30-config: executing...
deluge.1.m73zgk69hz2u#moby | [cont-init.d] 30-config: exited 0.
deluge.1.m73zgk69hz2u#moby | [cont-init.d] done.
deluge.1.m73zgk69hz2u#moby | [services.d] starting services
deluge.1.m73zgk69hz2u#moby | [services.d] done.
deluge.1.m73zgk69hz2u#moby | exec: fatal: unable to exec -e: No such file or directory
deluge.1.m73zgk69hz2u#moby | -e exited 111
deluge.1.m73zgk69hz2u#moby | [cont-finish.d] executing container finish scripts...
deluge.1.m73zgk69hz2u#moby | [cont-finish.d] done.
deluge.1.m73zgk69hz2u#moby | [s6-finish] syncing disks.
deluge.1.m73zgk69hz2u#moby | [s6-finish] sending all processes the TERM signal.
deluge.1.m73zgk69hz2u#moby | [s6-finish] sending all processes the KILL signal and exiting.
It seems that the service is failing for the volumes, but I do not understand why or how to fix it
-- UPDATE
I also have some mistakes in the service declaration (besides the right answer)
docker service create --name deluge \
--network p2pnetwork \
--replicas 1 \
-e PUID=501 -e PGID=20 \
-e TZ=ART \
-e UMASK_SET=022 \
-p 8112:8112 \
--mount type=bind,source=/Users/agus/Downloads/torrents,destination=/downloads \
--mount type=bind,source=/Users/agus/Downloads/torrents/config,destination=/config \
linuxserver/deluge
Also I need to change the download folders inside the deluge configuration and it worked
Docker Swarm Service uses a other syntax to mount volumes.
docker service create --name deluge \
--network p2pnetwork \
--replicas 1 \
linuxserver/deluge \
-e PUID=501 -e PGID=20 \
-e TZ=ART \
-e UMASK_SET=022 \
--mount type=bind,source=/Users/agus/Downloads/torrents/incoming,destination=/downloads \
--mount type=bind,source=/Users/agus/Downloads/torrents/config,destination=/config \
-p 8112:80
"--mount". Hopefully the volume is available on all your Swarm-Members, if you search for a good way to share volumes between Swarm-Nodes, i would suggest: GlusterFS

Error message: Make sure that `gem install pg -v '0.18.1'` succeeds before bundling

i have a problem with ruby. I tried a lot but nothing works for me.
When i want to start the rails server, i get this error message:
An error occurred while installing pg (0.18.1), and Bundler cannot continue.
Make sure that "gem install pg -v '0.18.1" succeeds before bundling.
This is what i tried already:
sudo install gem
bundle install
bundle install --path vendor/cache
gem install pg -v '0.18.1'
When i try gem install pg -v '0.18.1'i get this error message:
Could not find gem 'pg (>= 0) ruby' in any of the gem sources listed in your Gemfile or installed on this machine.
Run bundle install to install missing gems.
But bundle installdoesn't work either. I get this error message:
An error occurred while installing pg (0.18.1), and Bundler cannot continue.
Make sure that gem install pg -v '0.18.1' succeeds before bundling.
I also tried to start the server in a new ruby project.
Nothing helps..
Thanks for your help!
These are my changes in my Gemfile:
group :production do
gem 'pg'
gem 'rails_12factor'
end
group :development do
gem 'sqlite3'
end
If you're on Ubuntu, most likely you're missing a hidden dependency
sudo apt-get install libpq-dev
If you are on OS X, try these steps
Install Xcode command line tools (Apple Developer site). If you have
it already installed, update it using brew update.
brew uninstall postgresql
brew install postgresql
gem install pg
If you are an Ubuntu user you need to do the following prior installing the gem
sudo apt-get install libpq-dev
Then perform gem install pg -v '0.18.1' or just bundle install if you have you r gem in a GEMFILE.
If you are using Mac and Homebrew, Looks like libpqxx lib was missing.
brew install libpqxx
This command should do it.
If you are not sure where your pg_config is, and assuming you are on Linux or Mac, you can run the following command:
which pg_config
this will return ==> /usr/pgsql-9.1/bin/pg_config
now use this path as
bundle config build.pg --with-pg-config=/usr/pgsql-9.1/bin/pg_config
Done now bundle install
My teacher at Bloc had the solution! If anybody have the same problem run the following commands:
spring stop
gem uninstall pg
bundle install --without production
This solved my problem.
ARCHFLAGS="-arch x86_64" bundle install worked for me as discussed here.
Bundler has some problem identifing the PostgreSQL server path. If you are pretty sure that the your PostgreSQL server is installed properly, all you need to do should be adding the path to this to PATH variable. Example command:
export PATH=/path/to/postgres/bin/:$PATH
If you would still have some issues, it is very likely that you have something wrong with PostgreSQL install. If so, try installing Postgres.app and execute command as below:
export PATH=/Applications/Postgres.app/Contents/Versions/9.3/bin/:$PATH
Make sure that the version is correct.
Anyone running in to this (a year later!) using Rails 5.1.2 I did the following after first installing and initiating Postgresql (Centos 7).
So assuming you've already got postgresql installed and the postgres server&user set up.(+ the usual standard dev tools for Linux).
Add extra deps for rails to build gems.
$ sudo yum install postgresql-devel
Add postgres path in ~/.profile
export PATH=/usr/bin/postgres:$PATH (or your installed path)
Add another user/role with create db privileges using pgAdmin or shell
(should be the same user as the system/rails user because the postgres user doesn't have permissions for /rails/db/schema.rb, but the system/rails user does)
Below are shell commands for postgres create role and database.
$ sudo -u postgres psql (enter postgres password)
$ create role (linux/rails user) with createdb login password 'password';
$ \du (check its done and has createDB privs)
$ CREATE DATABASE name;
You will automatically become owner of the new database if no other arguments are presented.
Or you can use a gui like DBeaver to do the same.
So the above sets up for rails to access postgresql and build the pg gem once you've swapped out the default Gemfile & config/database.yml
Now create app and set it up (no need for -d postgresql flag because we swap out the Gemfile and the config/database.yml file contents completely and rails will install a postgresql db on bundle update/install.
(change some to rake for earlier versions of rails)
$ rails new app
$ cd app
$ atom (or editor) Gemfile config/database.yml
Swap out both file contents (to ones shown below) & save.
$ bundle update
$ bundle install
Check it with
$ rails db:create
(postgresql database should now be connected), so scaffold something
$ rails g scaffold Users name:string email:string comment:text
$ rails db:migrate
$ rails server
http://localhost:3000 shows the default page and http://localhost:3000/users brings up your new Users page using postgresql not sqlite3. Put something in to test it.
Below are the Gemfile and config/database.yml files I used for Rails 5.1.2, including taps for Heroku.
Gemfile rails 5.1.2
source 'https://rubygems.org'
gem 'rails', '5.1.2'
gem 'puma', '3.9.1'
gem 'sass-rails', '5.0.6'
gem 'uglifier', '3.2.0'
gem 'coffee-rails', '4.2.2'
gem 'jquery-rails', '4.3.1'
gem 'turbolinks', '5.0.1'
gem 'jbuilder', '2.7.0'
gem 'taps'
#Postgresql Database
group :production do
gem 'pg', '0.21.0'
end
group :development, :test do
gem 'sqlite3', '1.3.13'
gem 'byebug', '9.0.6', platform: :mri
end
group :development do
gem 'web-console', '3.5.1'
gem 'listen', '3.0.8'
gem 'spring', '2.0.2'
gem 'spring-watcher-listen', '2.0.1'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
config/database.yml file contents (watch out for indentation)
development:
adapter: postgresql
encoding: unicode
database: development or app_name
pool: 5
username: (user created for postgres/rails)
password: password
host: localhost
test:
adapter: postgresql
encoding: unicode
database: development or app_name
pool: 5
username: (user created for postgres/rails)
password: password
host: localhost
production:
adapter: postgresql
encoding: unicode
database: development or app_name
pool: 5
username: (user created for postgres/rails)
password: password
host: localhost
Doing all the above will get you a dev/prod postgresql database in rails but no test, you can also access the database directly from rails by just running "rails db" and entering password.
Its simple but gets you up and running with rails/postgresql quickly.
For Alpine linux, you'd want to install postgresql-dev first:
apk add --update postgresql-dev
Try install pg like this:
gem install pg -- --with-pg-dir=/path/to/postgresql/root
If it doesn't work, try
gem install pg -- --with-pg-include=/path/to/postgresql/root/include \
--with-pg-lib=/path/to/postgresql/root/lib
PostgreSQL setup on CentOS 6
[root#git2 ~]# yum install postgresql-server
[root#git2 ~]# 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"?
[root#git2 ~]# /etc/init.d/postgresql
Usage: /etc/init.d/postgresql {start|stop|status|restart|condrestart|try-restart|reload|force-reload|initdb}
[root#git2 ~]# /etc/init.d/postgresql start
/var/lib/pgsql/data is missing. Use "service postgresql initdb" to initialize the cluster first.
[FAILED]
[root#git2 ~]# service postgresql initdb
Initializing database: [ OK ]
[root#git2 ~]#
[root#git2 ~]# /etc/init.d/postgresql start
Starting postgresql service: [ OK ]
[root#git2 ~]# psql
psql: FATAL: Ident authentication failed for user "root"
[root#git2 ~]#
[root#git2 ~]# su - postgres
-bash-4.1$ psql
psql (8.4.13)
Type "help" for help.
postgres=# \l
List of databases
Name | Owner | Encoding | Collation | Ctype | Access privilege
s
-----------+----------+----------+-------------+-------------+-------------------
----
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
: postgres=CTc/postg
res
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
: postgres=CTc/postg
res
(3 rows)
postgres=#
postgres=# \q
-bash-4.1$
-bash-4.1$ pwd
/var/lib/pgsql
-bash-4.1$ wget -q http://www.commandprompt.com/ppbook/booktown.sql
-bash-4.1$ ls -lh booktown.sql
-rw-r--r-- 1 postgres postgres 42K Jan 11 2005 booktown.sql
-bash-4.1$ psql -f booktown.sql
CREATE DATABASE
(snip)
-bash-4.1$ psql
psql (8.4.13)
Type "help" for help.
postgres=# \l
List of databases
Name | Owner | Encoding | Collation | Ctype | Access privilege
s
-----------+----------+----------+-------------+-------------+-------------------
----
booktown | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
: postgres=CTc/postg
res
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
: postgres=CTc/postg
res
(4 rows)
postgres=#
postgres=# \q
-bash-4.1$
-bash-4.1$ pg_dumpall > /tmp/pg_dumpall.`date +%s`.sql
-bash-4.1$ ls -lh /tmp/pg_dumpall.1349195444.sql
-rw-r--r-- 1 postgres postgres 44K Oct 2 12:30 /tmp/pg_dumpall.1349195444.sql
-bash-4.1$
-bash-4.1$ pg_dump --clean booktown > /tmp/pg_dump-booktown.`date +%s`.sql
-bash-4.1$ ls -lh /tmp/pg_dump-booktown.1349196164.sql
-rw-r--r-- 1 postgres postgres 46K Oct 2 12:42 /tmp/pg_dump-booktown.1349196164.sql
-bash-4.1$
-bash-4.1$ psql booktown
psql (8.4.13)
Type "help" for help.
booktown=#
booktown=# \d
(snip)
public | subjects | table | postgres
public | text_sorting | table | postgres
booktown=# SELECT * FROM subjects;
0 | Arts | Creativity St
1 | Business | Productivity Ave
(snip)
PostgreSQL setup on Fedora 20
[root#localhost ~]# yum install postgresql-server
(snip)
[root#localhost ~]# systemctl start postgresql.service
Job for postgresql.service failed. See 'systemctl status postgresql.service' and 'journalctl -xn' for details.
[root#localhost ~]#
[root#localhost ~]# systemctl status postgresql.service
postgresql.service - PostgreSQL database server
Loaded: loaded (/usr/lib/systemd/system/postgresql.service; disabled)
Active: failed (Result: exit-code) since Sat 2014-01-18 08:08:38 EST; 12s ago
Process: 4921 ExecStartPre=/usr/bin/postgresql-check-db-dir ${PGDATA} (code=exited, status=1/FAILURE)
Jan 18 08:08:38 localhost.localdomain systemd[1]: Starting PostgreSQL database server...
Jan 18 08:08:38 localhost.localdomain postgresql-check-db-dir[4921]: "/var/lib/pgsql/data" is missing or empty.
Jan 18 08:08:38 localhost.localdomain systemd[1]: postgresql.service: control process exited, code=exited status=1
Jan 18 08:08:38 localhost.localdomain systemd[1]: Failed to start PostgreSQL database server.
Jan 18 08:08:38 localhost.localdomain systemd[1]: Unit postgresql.service entered failed state.
[root#localhost ~]#
[root#localhost ~]# postgresql-setup initdb
Initializing database ... OK
[root#localhost ~]#
[root#localhost ~]# systemctl start postgresql.service
[root#localhost ~]#
[root#localhost ~]# systemctl stop postgresql.service
[root#localhost ~]#
[root#localhost ~]# cp -a /var/lib/pgsql/data/pg_hba.conf /var/lib/pgsql/data/pg_hba.conf.orig
[root#localhost ~]# # insecure... just for dev...
[root#localhost ~]# vim /var/lib/pgsql/data/pg_hba.conf
[root#localhost ~]# diff /var/lib/pgsql/data/pg_hba.conf.orig /var/lib/pgsql/data/pg_hba.conf
80c80
< local all all peer
---
> local all all trust
82c82
< host all all 127.0.0.1/32 ident
---
> host all all 127.0.0.1/32 trust
[root#localhost ~]#
[root#localhost ~]# systemctl start postgresql.service
[root#localhost ~]#
[root#localhost ~]# su - postgres
-bash-4.2$ psql -c '\du'
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------+-----------
postgres | Superuser, Create role, Create DB, Replication | {}
-bash-4.2$ psql -c "CREATE ROLE pguser1 UNENCRYPTED PASSWORD 'secret1' NOSUPERUSER CREATEDB CREATEROLE NOINHERIT LOGIN"
CREATE ROLE
-bash-4.2$ psql -c '\du'
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------+-----------
pguser1 | No inheritance, Create role, Create DB | {}
postgres | Superuser, Create role, Create DB, Replication | {}
-bash-4.2$
-bash-4.2$ psql -c '\l'
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(3 rows)
-bash-4.2$
-bash-4.2$ psql -c "CREATE DATABASE pgdatabase1 WITH OWNER = pguser1"
CREATE DATABASE
-bash-4.2$ psql -c '\l'
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-------------+----------+----------+-------------+-------------+-----------------------
pgdatabase1 | pguser1 | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(4 rows)
-bash-4.2$

Combine netstat command and geoiplookup

how can I combine the following command:
netstat -atun | awk '{print $ 5}' | cut-d: f1 | -e sed '/ ^ $ / d' | sort | uniq-c | sort-n
and "geoiplookup" listing something like "Con. Number, IP, Country"
I am using this lib:
http://kbeezie.com/geoiplookup-command-line/
Thank you for your help!
best regards
You should be able to get it with something like this:
netstat -an -f inet | awk '{print $ 5}' | sed -e '/^\*\.\*$/d' | awk 'sub(/\.[0-9]+$/,"")' | uniq | sort -n | xargs -n 1 geoiplookup { } | sort | uniq -c | sort -n | sed -r 's/ GeoIP Country Edition://g'
netstat -an -f inet - shows all network related data structures with network addresses as numbers and pulls the inet address family
awk '{print $ 5}' - takes that input and presents only the ip address with port from the prior.
sed -e '/^\*\.\*$/d' - strips out all of the . lines
awk 'sub(/\.[0-9]+$/,"")' - strips the port number leaving the ip address alone
uniq - gets rid of the duplicate ips
sort -n - performs a numeric sort (not necessary)
xargs -n 1 geoiplookup { } - takes the first input an performs the lookup for the country
sort - sorts based on country name
uniq -c - groups the country names with a count
sort -n - organizes the countries based on the count
sed -r 's/ GeoIP Country Edition://g' - Strips the phrasing "GeoIP Country Edition:"
This has little to do with brute force, other than telling you which country the connections are coming from.

Postgres database says database exist but I cannot Alter owner

This is my first VPS and first rails project ever.
Inside of postgres console:
postgres=# \list
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------------+----------+----------+-------------+-------------+-----------------------
blog_production | blog | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(4 rows)
postgres=# ALTER DATABASE blog_development OWNER TO watashi;
ERROR: database "blog_development" does not exist
How can it not exist when it obviously is on the list? How can I drop this database? and if I can it hurt my vps?
Link to site is: www.morningharwood.com
it doesnt error out until www.morningharwood.com/works
Rails can't find the works table, it should have been created as part of your RAILS_ENV=production bundle exec rake db:migrate command, what was the output of that?
Also check that you are running the rails server in production mode.

Resources