PostgreSQL Installation on Ubuntu
15K views
Dec 11, 2024
This video discusses how to install PostgreSQL on an Ubuntu 21.04 machine. 0:00 Introduction 0:20 Open Terminal 0:22 Update Packages 0:38 Install PostgreSQL Package 1:03 Login as Postgres User 1:15 Login to PSQL Database 1:29 Create User Database 2:30 Create User Role 3:47 Grant User Permissions 4:13 Create Stock and Crypto Database #databases #postgresql #ubuntu
View Video Transcript
0:00
hello everyone today we're going to
0:02
install the postgres database on an
0:05
ubuntu machine
0:06
now if you're here i'm assuming you
0:08
already know what a database is and you
0:10
know what postgres is so we're going to
0:12
cut right to the commands
0:15
so with that being said let's open up
0:17
our terminal
0:19
and then we'll first update our packages
0:22
so sudo app update dash yes hit enter
0:26
from the password
0:31
and then it'll update the existing
0:32
packages
0:33
now with the updates out of the way we
0:36
want to go ahead and install postgres
0:39
which is easy to do
0:40
sudo
0:41
apt install
0:43
and then we need to type in the correct
0:45
packages post sql
0:47
postgresql and trip
0:51
and it's that easy now when we install
0:54
postgres
0:56
or
0:56
psql it also adds to the postgres user
1:00
so what we now want to do
1:03
is sudo switch the to switch to that
1:06
user postgres so it's sudo i space dash
1:09
u space postgres and you'll notice now
1:12
i'm logged in as the postgres user
1:14
and i can now issue the psql command
1:17
which will log me into the postgres
1:19
database
1:20
you can list the existing database
1:23
database is
1:25
okay so now that you know we've
1:27
successfully installed postgres now what
1:29
we want to do
1:31
two things
1:32
one we first want to
1:34
create
1:35
our then create a database with the same
1:39
name as our login so that allows us to
1:41
not it allows us to log in automatically
1:44
right so
1:46
we'll go ahead i'll show you what i mean
1:47
by that so psql
1:50
right so leo smiggle does not exist so
1:53
let's switch back to the postgres user
1:56
with psql again
1:58
create
2:00
database
2:05
grab the semicolon okay so now that
2:07
creates the database right
2:10
now what we want to do is we want to
2:14
put it out
2:15
right
2:16
exit again ps4
2:19
it still says leo smile does not exist
2:22
so that's one concept i want you to
2:24
understand is that you know there's both
2:26
a database and a database
2:29
user so create
2:31
user
2:33
yes google
2:36
password
2:38
and we'll just say
2:41
database
2:42
all right nothing real
2:45
okay
2:46
grant all privileges
2:52
c-r-i-v-i-l-e-g-e-f
2:55
on
2:59
two
3:03
print all yeah
3:04
on
3:08
up
3:09
on database leos mingle to leo smiggle
3:12
okay now quit
3:14
exit esql okay now i'm logged in
3:18
automagically
3:20
okay so now we see
3:22
that i have a database and a user even
3:26
though i didn't have to type in
3:28
my database password although whenever
3:29
i'm connecting if i connect as my user
3:32
on the i would need that password
3:34
but regardless
3:36
i'm able to log in again automatically
3:41
now what we want to do
3:42
let's create
3:44
uh database let's say we'll call it
3:46
alpha that won't give that'll give me an
3:49
error because i've only granted
3:52
permissions
3:53
to
3:55
my that specific database so you can
3:57
create
4:00
you know your user as a super user if
4:02
you want i'm not going to do that i like
4:04
to grant specific permissions so let's
4:06
just um
4:08
go ahead and switch back to the post
4:10
press user
4:12
dsql say we want to create
4:14
a database
4:17
fittingly named alpha
4:19
right now we can list it
4:21
and now we have alpha as our database so
4:24
this would be the database that we're
4:25
going to
4:26
install all of our price data or what
4:28
you know for for specifically for this
4:30
channel
4:31
um
4:32
all of our price data on
4:35
they're in
4:36
and they're fundamental and technical
4:38
etc but right leo spindle does not have
4:41
access to this database at the moment
4:43
only postgres does because we created it
4:45
so now we need to grant
4:49
all privileges on
4:52
database alpha
4:57
okay now we can quit you can exit and we
4:59
can do pfql connect right list right
5:02
connect alpha
5:04
now dt there are no
5:06
tables but we now have full access to
5:10
alpha
5:11
so that's it it's pretty simple to
5:14
install postgres
5:16
it gets a little bit more challenging if
5:18
you want to use a docker container
5:19
because you know you typically want to
5:21
have your volume
5:23
on a separate drive once you start
5:26
getting larger volumes but for our
5:29
purposes and the purposes of this
5:31
channel
5:32
a
5:32
psql instance you know on a bare metal
5:36
we'll call it a bare metal um
5:38
system is perfectly fine and we don't
5:40
run into any memory issues or anything
5:42
like that too so if you like this
5:44
feature and it helped you out please
5:45
give it a like and
5:48
you know good luck on your postgres
5:50
journey thanks