Setting up a PostgreSQL db for Ruby on Rails locally - macos

I'm stumbling on the real basics because I cannot find any clear directions.
I have installed Postgres.app 9.3.5 on OS X.
The documentation tells me how to create a database, createdb mydb, but to use it I'd need a PostgreSQL user and a password for that user.
What are the basic steps to create a PostgreSQL user with a password (and a database if different than the above) on a local PostgreSQL install?

The Postgres.app documentation used to explain this, but appears to have been split up and cut short recently.
You don't need a dedicated user; you can simply use the default postgres user. However, because that's a superuser, you're wise to create less privileged users for your apps.
You generally want to make a database owned by the app's user, as Rails expects to be able to use the same user to change the schema with migrations as it does to run queries. (It's not great security-wise, but it's the path of least resistance with Rails).
So create the user, then create the db.
Here's how it should look. Don't type the prompts ($ or postgres=#), they're there to show what you're running. Just enter the commands after the prompts.
$ psql -q
postgres=# CREATE USER myapp WITH ENCRYPTED PASSWORD 'mypassword';
postgres=# CREATE DATABASE myappdb OWNER myapp;
postgres=# \q
You may now specify the user, password and database in your database.yml.
(Note that Postgres.app may be configured not to require passwords; in this case the password will be ignored by PostgreSQL).

createdb mydb
psql -s mydb
create user space_pilot password 'hello';
GRANT ALL PRIVILEGES ON DATABASE mydb TO space_pilot;

Related

Sequel gem copy database to another with username and password

From the section to copy another use is to use
sequel -C mysql://host1/database postgres://host2/database2
Is there a way to include username and password for both databases.
Tried with no luck
sequel -C mysql://user:password#host1/database postgres://user2:password2#host2/database2
The usernames and passwords are stored in the user database. You first need to setup a user on your target database. Before that you can't copy anything to it. Copying the user database from mysql to postgres is not going to work either imho so you will have to setup your user manually first.

Oracle 12c default pluggable DB in sqlplus

I have a pluggable database in Oracle 12c named PDBORCL.
After a server restart something changed in how to connect to it.
I created a user in that pluggable DB, for the example the user is PETER and the password is also PETER. Before the restart I used to be able to open a Command Prompt, run sqlplus, which would in turn ask for my username and then its password, and it would sign in. Now this does not work, it says invalid username/password. When I log in with SYS and check:
SELECT * FROM dba_users WHERE username = 'PETER';
I get no results.
However, if I sign in using the following from a command prompt, it works:
sqlplus PETER/PETER#PDBORCL
So, the DB is up and running, but it seems to be connecting by default to the wrong pluggable DB. I need to change it to the way it was before the restart, so that it connects by default to that specific pluggable DB.
How can I achieve this?
I found the solution. Change or create the environment variable LOCAL (in Windows) to PDBORCL. I think I read in linux the variable is TWO_TASK. After changing it, the following works:
sqlplus PETER/PETER
Also, just calling sqlplus and waiting to be prompted for username and password works.
You have created a user in pluggableDB and this user is not visible beyond the pluggable DB hence the reason you dont see user PETER when running the above query as sys..
If you want to connect to your pluggable DB directly what you have done above is right else you to connect to sys and the use CONNECT command.

How to create a user in Oracle SQL developer

I am newbie to oracle sql developer 3.1.07.42, and have just installed it on my machine. I want to make a new connection, but it requires a user and a password which I do not know. I have been googling about it since many days, and have learned that there are some commands to create user, but I do not know where should I run those commands, because I cannot run queries/commands until the connection is created.
Would anyone let me know what should I do?
Steps for creating new user :
1)Open Sql Developer, make new connection.
2)Login with System username and password(made during installation).
3)Once you connect, expand the System user (under Connections, in the left pane) and scroll down to Other users. Then right click users and add new user.
4)Give its username and password & select appropriate system privilege.
5)You are done now, check by making new connection.
Use this below simple commands to create an user
-- Create a user
CREATE USER youruser IDENTIFIED BY yourpassword;
--Grant permissions
GRANT CONNECT, RESOURCE, DBA TO demo;
you should install database software in your local pc/laptop then create user in the database and you can connect the database via sql developer by key in username and password that already created.If you want to connect to other database same step like the previous step but before that you need to point to the remote database.
I thinks you should use "Database Configuration Assistant" to create new database and U can set user name and password and use it in oracle SQL Developer!!!

How do I connect to a postgres database with Sequel?

I was making a web app to deploy using Heroku.com when I realized that the only database type they support is PostgreSQL. Up until now, my app (powered by the Ruby gem Sinatra) accessed the database via the .Sqlite method for the Sequel gem.
Here's my Ruby script from when I used Sequel to access the .db file via SQLite:
DB = Sequel.sqlite('mydatabase.db')
DB.create_table :mytable do
primary_key :id
String :column_name
end
I installed PostgreSQL after learning Heroku used only that. Here's the script via postgres (my username is literally 'postgress', though I obviously won't reveal my password in this question):
DB = Sequel.postgres('mydatabase.db',:user=>'postgres',:password=>'my_password_here',:host=>'localhost',:port=>5432,:max_connections=>10)
DB.create_table :mytable do
primary_key :id
String :column_name
end
However, when I run this code, I get the following error:
C:/Ruby193/lib/ruby/gems/1.9.1/gems/sequel-3.38.0/lib/sequel/adapters/postgres.rb:208:in 'initialize': PG::Error: FATAL: database "mydatabase.db" does not exist (Sequel::DatabaseConnectionError)
I've tried searching Google, StackOverflow, Sequel documents, and the Heroku help documents for any help, but I've found no fix to this problem.
Does anyone know what I am doing wrong?
The database mydatabase.db doesn't exist, as per the error message from Pg. Likely reasons:
You probably meant mydatabase without the SQLite-specific .db filename suffix
It's possible you created the db with different case, eg "Mydatabase.db";
You might be connecting to a different Pg server than you think you are
You never created the database. Unlke SQLite's default behaviour, Pg doesn't create databases when you try to connect to a database that doesn't exist yet.
If in doubt, connect to Pg with psql and run \l to list databases, or connect via PgAdmin-III.
The PostgreSQL documentation and tutorial are highly recommended, too. They're well written and will teach you a lot about SQL in general as well as Pg in particular.
BTW, the postgres user is a superuser. You should not be using it for your application; it's like running your server as root, ie a really bad idea. Create a new PostgreSQL user without superuser, createdb or createuser rights and use that for your application. You can either CREATE DATABASE somedb WITH OWNER myappuser - or preferably, create the database owned by a different user to your webapp user and then expicitly GRANT the webapp user the minimum required permissions. See user management and GRANT.
On heroku all you need to do is tell Sequel to connect to the content of the DATABASE_URL environment variable (which is a properly formed url that Sequel understands):
DB = Sequel.connect(ENV['DATABASE_URL'])

What username & password should be entered when connecting to SQL*Plus after installing Oracle 11g?

I have installed Oracle 11g on Windows 7
When I start sqlplus, it ask me for a username and password
Can anybody tell me what username needs to be inserted and when I try to type in any password, it doesn't allow me to type a single letter. Is there a reason why?
If you've forgotten the password for any user then you can reset by logging in as SYS:
sqlplus / as sysdba
And then:
alter user <username> identified by <password>;
If you've forgotten which users you have then you can run:
select username from all_users;
If you have only recently created the database it would be worthwhile restricting on CREATED, as the default database install comes with dozens of its own schemas. For instance, to find users added in the last week run this:
select * from all_users
where created > trunc(sysdate)-7;
Enter SYSTEM as user-name and the password entered during installing 11g works well for me!
The username refers to the schema to which you must connect to. Generally the hr schema is the sample schema that is available. The password will be the same password that you set during Oracle installation.

Resources