-1

I run the following command in my windows powerShell

su postgres

su : The term 'su' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1

  • su postgres
  • ~~
    • CategoryInfo : ObjectNotFound: (su:String) [], CommandNotFoundException
    • FullyQualifiedErrorId : CommandNotFoundException
  • 2
    `su` is a Unix command, short for "switch user". You are obviously reading the documentation for the wrong operating system. – Selcuk Aug 25 '20 at 05:44
  • Thank you for helping me I'm reading a book called django 3 by example in which author doesn't explain for what system this comand is going to use i have no experience with PostgerSQL. Can you help me please how to do it same in windows, I will give you details what I'm trying to do... –  Aug 26 '20 at 17:45
  • I just checked out the book and you are right, the author makes a little mistake on that page by not disclosing that the `su` command is for Linux or MacOS only. You can simply use the pgAdmin tool installed with the PostgreSQL for Windows to create a new user (login role) and a database. – Selcuk Aug 26 '20 at 23:08

2 Answers2

1

As for creating a new user for your PostgreSQL database from the command prompt, try the following instructions:

After finishing the PostgreSQL installation, make sure you check and copy the Installation Directory, in my case, is 'C:\Program Files\PostgreSQL\13'.

Then follow 'Mycomputer => properties => advanced system settings=> Environment Variables => System Variables', select 'Path' and click 'Edit', in which you`ll addin path 'C:\Program Files\PostgreSQL\13\bin' and 'C:\Program Files\PostgreSQL\13\lib' and save change.

Next open command prompt:

cd C:\
psql --version

you`ll see the psql version that installed, with all is set:

psql -U Postgres

the command above connect you to the Database Superuser: Postgres, after applying the password that you create during the process of installation.

psql (13.1)
Type "help" for help.

postgres=#

comments above inform you`re connected. Now create a new user and database in commands:

create database yourdatabasename;
create user yourusername with password 'password';

Apply your own name and password, and don`t forget the semicolon ';', you can also check the List of databases:

\l

The last thing you need to do is to grant privilege for the new database to the new user:

grant all on database yourdatabase to yourusername;

If you want to connect to the database you`ve just created:

\q

to exit, and then,

psql -d databasename -U username
Dharman
  • 30,962
  • 25
  • 85
  • 135
Liang Wei
  • 163
  • 9
0

Well in Windows there is no sudo/su command. The nearest alternative is "run as administrator."

You can do this using the runas command with an administrator, or alternatively by right-clicking the program in the UI and choosing "run as administrator."

Amjad Shahzad
  • 706
  • 5
  • 12
  • Thank you for helping me I'm reading a book called django 3 by example in which author doesn't explain for what system this comand is going to use i have no experience with PostgerSQL. Can you help me please how to do it same in windows, I will give you details what I'm trying to do... - I'm trying to add full text search in my blog web application using PostgerSQL, i installed it and tring to create user in book author use following commands $Su postgres --- $createuser -dp blog --- $createdb -E utf8 -U blog blog --- if you know what to do or what I'm trying to do please Help me out. –  Aug 26 '20 at 17:54