> This page location: Roles & Privileges > CURRENT_USER
> Full Neon documentation index: https://neon.com/docs/llms.txt

# PostgreSQL CURRENT_USER

**Summary**: in this tutorial, you will learn how to use the PostgreSQL `CURRENT_USER` function to return the name of the currently logged-in database user.

## Introduction to the PostgreSQL CURRENT_USER function

The PostgreSQL `CURRENT_USER` is a function that returns the name of the currently logged-in database user.

Here's the syntax of the `CURRENT_USER` function:

```sql
CURRENT_USER
```

The function returns the name of the current effective user within the session.

In other words, if you use the [`SET ROLE`](https://neon.com/postgresql/postgresql-administration/postgresql-set-role) statement to change the role of the current user to the new one, the `CURRENT_USER` will reflect the new role.

In PostgreSQL, a role with the `LOGIN` attribute represents a user. Therefore, we use the terms role and user interchangeably.

To get the original user who connected to the session, you use the `SESSION_USER` function.

## PostgreSQL CURRENT_USER function example

First, open the command prompt on Windows or a terminal on Unix-like systems and connect to the PostgreSQL server using psql:

```bash
psql -U postgres
```

Second, use the `CURRENT_USER` function to get the currently logged-in user:

```sql
SELECT CURRENT_USER;
```

Output:

```text
 current_user
--------------
 postgres
(1 row)
```

Third, [create a new role](https://neon.com/postgresql/postgresql-administration/postgresql-roles) called `bob`:

```sql
CREATE ROLE bob
WITH LOGIN PASSWORD 'SecurePass1';
```

Fourth, change the role of the current user to `bob`:

```sql
SET ROLE bob;
```

Fifth, execute the `CURRENT_USER` function:

```sql
SELECT CURRENT_USER;
```

It returns `bob` instead:

```text
 current_user
--------------
 bob
(1 row)
```

Six, use the `SESSION_USER` function to retrieve the original user who connected to the session:

```sql
SELECT SESSION_USER;
```

Output:

```text
 session_user
--------------
 postgres
(1 row)
```

The `SESSION_USER` function returns `postgres`, not `bob`.

## Summary

- Use the `CURRENT_USER` function to return the current effective user within the session.
- Use the `SESSION_USER` function to return the original user who connected to the session.

---

## Related docs (Roles & Privileges)

- [Create Roles](https://neon.com/postgresql/postgresql-administration/postgresql-roles)
- [Grant Privileges](https://neon.com/postgresql/postgresql-administration/postgresql-grant)
- [Revoke Privileges](https://neon.com/postgresql/postgresql-administration/postgresql-revoke)
- [Alter roles](https://neon.com/postgresql/postgresql-administration/postgresql-alter-role)
- [Drop Roles](https://neon.com/postgresql/postgresql-administration/postgresql-drop-role)
- [Role Membership](https://neon.com/postgresql/postgresql-administration/postgresql-role-membership)
- [SET ROLE Statement](https://neon.com/postgresql/postgresql-administration/postgresql-set-role)
- [List Roles](https://neon.com/postgresql/postgresql-administration/postgresql-list-users)
- [Change Password](https://neon.com/postgresql/postgresql-administration/postgresql-change-password)
- [Create Superusers](https://neon.com/postgresql/postgresql-administration/create-superuser-postgresql)
- [PostgreSQL Row-Level Security](https://neon.com/postgresql/postgresql-administration/postgresql-row-level-security)
