user "example" was not authenticated (Peer) - sql

Hello I have such users in my db
I want to delete user postgres so I
DROP USER postgres;
I get the error
ERROR: current user cannot be dropped
After this I try to switch on another user:
postgres=# \connect postgres andrey
and I get the error
FATAL: Peer authentication failed for user "andrey"

The first error message is self-explanatory.
To connect as andrey, you'll have to edit pg_hba.conf and add a line like the following at the very top:
local postgres andrey trust
Then reload the configuration with
SELECT pg_reload_conf();
and you will be able to login as user andrey.
But it is impossible to drop the “bootstrap superuser” postgres. I don't see why that is necessary though. You need a superuser, and if you don't like the name postgres for some reason, you can rename it.
But my advice is to leave user postgres with that name – it is customary to name the bootstrap superuser postgres.

Related

psql says password is incorrect for user that does not exist

I am trying to create a database and each time I run the createdb [databasename], and enter the "incorrect" password, command I get the following error, createdb: error: could not connect to database template1: FATAL: password authentication failed for user "[username]".
However, the user that says the authentication has failed for doesn't exist. I can run psql -U postgres and enter the password I provided previously and log in just fine. Once logged in as Postgres user I run \du and only see the Postgres user in the table. Any reason this would be happening? I uninstalled and reinstalled and still have the same issue. Why is the default user something other than the original postgres user?
Here is the result of the \du command
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------------------+-----------
postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
The error message does not tell you the exact reason why authentication failed on purpose, to give attackers as little information as possible.
The cause of your problem might be that your username contains upper case letters on the operating system, but you created the database user without using double quotes, so that the upper case letters got translated to lower case.
If you want more than guessing, you have to tell us the exact command line and the output from \du.
I guess I had to add the username from my OS because that is what Postgresql defaults to, as well as add a DB with the same name.

How to solve ERROR: must be member of role "postgres"

I am very new to postgres. One of my project is using an RDS postgres instance, the application team created a user and use that user to create the database.
I am trying to grant default privilege to the default postgres user to this application database by running the command below but I am getting an error message.
ALTER DEFAULT PRIVILEGES
FOR USER postgres
IN SCHEMA public
GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO postgres;
Error message
ERROR: must be member of role "postgres"
SQL state: 42501
Please advise how I can grant default privilege to postgres user for the database.
You must connect as a superuser to run this command.
I misunderstood my case earlier. Apparently, postgres user was the owner of the database not the app user. So I logged in as postgres and executed the command and it works.
If you did a pgdump to export the database, and then were getting this error on trying to import it. Use -O when creating the pgdump - https://www.postgresql.org/docs/current/app-pgdump.html

SQL Server User Mapping Error 15023

I try to map my other DB to a user by going to Security > Logins > right click someuser > Properties > User Mapping > Select DB > set as db_owner and then ok, but I keep on getting an error saying
User, group, or role 'someuser' already exists in the current database. (Microsoft SQL Server, Error: 15023)
What is causing the error, and how do I map that user to the database?
To fix the user and login mapping you need to open a query window in the SQL Server Management Studio. Enter the following two lines and replace myDB with the database name and myUser with the correct user name:
USE myDB
EXEC sp_change_users_login 'Auto_Fix', 'myUser'
If run successfully you should get an output like this one:
The row for user '****' will be fixed by updating its login link to a login already in existence.
The number of orphaned users fixed by updating users was 1.
The number of orphaned users fixed by adding new logins and then updating users was 0.**
Your user should now be mapped correctly.
Edit:
New way to Resolve/Fix an Orphaned User:
In the master database, use the CREATE LOGIN statement with the SID option to recreate a missing login, providing the SID of the database user.
CREATE LOGIN <login_name>
WITH PASSWORD = '<use_a_strong_password_here>',
SID = <SID>;
To map an orphaned user to a login which already exists in master, execute the ALTER USER statement in the user database, specifying the login name.
ALTER USER <user_name> WITH Login = <login_name>;
When you recreate a missing login, the user can access the database using the password provided. Then the user can alter the password of the login account by using the ALTER LOGIN statement.
ALTER LOGIN <login_name> WITH PASSWORD = '<enterStrongPasswordHere>';
if it is just one or two users, then easiest way is to drop the database user from the restored database, remap the database user to the server login using SSMS. If the server login does not exist then just create it, map the user.
Option 2: If you are migrating a large number of users, use sp_help_revlogin. sp_help_revlogin is a Microsoft supplied stored procedure that will help migrate logins from one server to another, including passwords and SIDs. Here is a good article about it SP_HELP_REVLOGIN : http://www.databasejournal.com/features/mssql/article.php/2228611/Migrating-Logins-from-One-SQL-Server-to-Another.htm
Code patches to help use it :
run following T-SQL Query in Query Analyzer. This will return all the existing users in database in result pan.
USE YourDB
GO
EXEC sp_change_users_login 'Report'
GO
Run following T-SQL Query in Query Analyzer to associate login with the username. ‘Auto_Fix’ attribute will create the user in SQL Server instance if it does not exist. In following example ‘ColdFusion’ is UserName, ‘cf’ is Password. Auto-Fix links a user entry in the sysusers table in the current database to a login of the same name in sysxlogins.
USE YourDB
GO
EXEC sp_change_users_login 'Auto_Fix', 'ColdFusion', NULL, 'cf'
GO
Run following T-SQL Query in Query Analyzer to associate login with the username. ‘Update_One’ links the specified user in the current database to login. login must already exist. user and login must be specified. password must be NULL or not specified
USE YourDB
GO
EXEC sp_change_users_login 'update_one', 'ColdFusion', 'ColdFusion'
GO
2) If login account has permission to drop other users, run following T-SQL in Query Analyzer. This will drop the user.
USE YourDB
GO
EXEC sp_dropuser 'ColdFusion'
GO
Create the same user again in the database without any error.
If you assign permissions to a database user without mapping it to the database first, it throws the error you mentioned.
You should be able to delete the user, map it to the database and then assign the user to the db_owner role.
First drop your user, then execute the script below:
USE [YOURDB]
GO
CREATE USER [USERNAME] FOR LOGIN [USERNAME]
GO
USE [YOURDB]
GO
ALTER USER [USERNAME] WITH DEFAULT_SCHEMA=[dbo]
GO
I had the problem when I was trying to copy a production database to a local test database. In SSMS, I made sure to disconnect from the production server before executing scripts on the local. However, even though I thought I had disconnected, someone pointed out that the title of the production database was still there, and I got errors that objects were already there. The solution was to totally exit from SSMS and start it again, only connecting to the local test database that time.
you can solve problem by expand database ->Security -> Users
and delete the user 'someuser' ,after that go to user mapping and assign.
this problem happen some times because the database user 'someuser' was deleted from 'Logins' in Security section in SSMS and the database still own this user
Create failed for User (Microsoft.SqlServer.Smo)
SQL Server Error User, group, or role already exists in the current database. (Microsoft SQL Server, Error: 15023)
To fix above error delete user under each database individually

Request access to nearby Oracle database, need update statement (ora-01031)

I've got
url: jdbc:oracle:thin:#195.123.456.789:1521:someSID
User: artem
Password: unchangeableForAllUsers
I'm also got second DB, all the same, changing only the name
url: jdbc:oracle:thin:#195.123.456.789:1521:someSID
User: denis
Password: unchangeableForAllUsers
How can I make update query from one DB to other? Using pl/sql I've got next message from Web-browser, when I try to change artem.table to denis.table:
ORA-01031: insufficient privileges
SQL Statement ignored
When I try to save changes in artem pl/sql package(query to denis db, like that
update denis.table dt
set dt.someColumn=1
where dt.ID=3305;
), see next in my IDE:
PL/SQL ORA-00942: User table or view does not exist
While I'm in IDE, logged like artem, I can to change and commit other users db free, from IDE SQL console.. maybe couse they have the same url and password? How can I save my query
update denis.table dt
set dt.someColumn=1
where dt.ID=3305;
in artem package for get access(update cell) to nearby database from Web-site, when i logged there like artem.
Thanks
As described, this is not a jdbc or plsql issue but rather a permissions issue.
You are connecting to the same database, but as two different users. In Oracle, a user has their own schema (same name as the user). If you wish to access data in schema A from schema B, schema A must GRANT permissions to schema B.
For example, if you want the user "artem" to have permission to UPDATE table "mytable" in schema "denis", log into the account "denis" and GRANT UPDATE permission to "artem":
-- While logged in as "denis"
GRANT UPDATE ON mytable TO artem;
Now you can log in as "artem" and query "denis.mytable". Grants you may want to give: SELECT, INSERT, UPDATE, DELETE. This, of course, works both ways (if you want user "denis" to have access to "artem" objects, then "artem" must GRANT permission to "denis".

ORA-01031 Insufficient privileges while CREATING a VIEW?

When I try to create a view that including different tables I'm getting the following error:
Error at Line 1:
ORA-01031 Insufficient privileges.
Could anyone tell me what could be the problem. I tried following the another stackoverflow post mentioned here but it's pertaining to
different schemas.
ORA-01031: insufficient privileges when selecting view
Please let me know as I'm new here.
My Query is as follows:
ORiginal Question:Create a view to select employee ID, employee name, hire date, and department number.
MY SOLUTION:
CREATE VIEW SIMPVIEW AS
SELECT EMPNO, ENAME, HIREDATE,DEPTNO
FROM EMP;
Then probably you may not have the privileges to perform the CREATE VIEW command in your database schema... Log in into SYSDBA account and issue the command
GRANT CREATE VIEW TO <dbusername>;
Here <dbusername> should be replaced with the name of the user you want to give access to the CREATE VIEW command.
You can check if your user has VIEW creation privileges using select * from session_privs.
Note that to be able to create a view, the user that is creating it needs to have been granted SELECT privileges on all the objects being used, as well as the mentioned CREATE VIEW privilege. You can also check that by querying to USER_TAB_PRIVS with the user getting the error.
when I wanted to execute the above query in sql developer I faced issues as I did not have enough privileges to create a view or other oracle object schema such as trigger, packages, procedures etc. I found the error to i.e. “Error at Line 1: ORA-01031 Insufficient privileges”. so, I needed the all privileges to practice all these queries and programs. I took the following steps in order to solve my problem:
As I logged in as a user name ‘scott’, so my name is ‘scott’ not ‘Dhruv’. My ambition was to grant all the privileges to me i.e. to the user ‘scott’.
For that, I need to enter in the database as a DBA. Now, question is! How to log in as DBA. For this, I opened command prompt and I logged in the database as sysdba by following the below steps:
a) In window run, I typed cmd to open command prompt. I typed: sqlplus /nolog which means that I logged in without providing required credentials.
b) I authenticated myself for my underlying O/S and entered in database as DBA. For that, I typed in command prompt: connect / as sysdba;
c) I evaluated who is the DBA user in my database if exists. For that I typed: select name from V$database;
d) Here we go after this command. I finally granted myself (scott) to create view in sql developer by typing the command: grant create view to scott;
e) Finally, I granted myself all the privileges by typing: grant all privileges to scott;
Snapshot of command prompt: I have attached.
Finally, I executed and created my view: I have attached
I had this error, and the solution was to grant select WITH GRANT OPTION
to a table from another schema that was included in the view.
At first You need to give the user authentication so you need to know who dba in normal the system give this authentication so make conn system/ *password*
give grand or authentication by put grant create view to *DataBaseUsername*;
make the connection to your user and apply your command
You have to give select any table privilege to the user. Then the view will compile successfully. No need to explicitly grant select to the user to all the objects.