Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianbiro committed Dec 3, 2023
1 parent afb42e4 commit 1871a9e
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 40 deletions.
39 changes: 37 additions & 2 deletions content/Data/SQLnotes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# SQL Notes

## .psqlrc

```
\set ON_ERROR_ROLLBACK interactive
\set COMP_KEYWORD_CASE upper
Expand All @@ -17,7 +18,9 @@
```

## Useful PostgreSQL

### Get percent change

```sql
CREATE OR REPLACE FUNCTION
percent_change(new_value numeric,
Expand Down Expand Up @@ -50,7 +53,9 @@ SELECT relname as "Table",
FROM pg_catalog.pg_statio_user_tables
ORDER BY pg_total_relation_size(relid) DESC;
```

### Settings

```sql
select
name,
Expand All @@ -60,7 +65,9 @@ select
from
pg_settings;
```

### Locks

```sql
SELECT
bl.pid AS blocked_pid,
Expand All @@ -77,7 +84,9 @@ FROM
WHERE
NOT bl.granted;
```

### Connection info

```sql
select
usename,
Expand All @@ -87,7 +96,9 @@ from
group by
usename;
```

### Show Activity

```sql
select
datname,
Expand All @@ -102,7 +113,9 @@ select
from
pg_stat_activity;
```

### Waits

```sql
SELECT
pg_stat_activity.pid,
Expand All @@ -116,7 +129,9 @@ WHERE
pg_stat_activity.query !~ '%IDLE%' :: text
AND pg_stat_activity.waiting = true;
```

### Dbsize

```sql
SELECT
datname,
Expand All @@ -126,7 +141,9 @@ FROM
ORDER BY
db_size;
```

### Uselesscol

```sql
SELECT
nspname,
Expand Down Expand Up @@ -167,12 +184,16 @@ ORDER BY
relname,
attname;
```
### Uptime

### Uptime

```sql
select
now() - pg_postmaster_start_time() AS uptime;
```

### Show running queries

```sql
SELECT
pid,
Expand All @@ -188,14 +209,18 @@ WHERE
ORDER BY
query_start desc;
```

### Kill query

```sql
-- Kill running query
SELECT pg_cancel_backend(pid);
--- Kill idle query
SELECT pg_terminate_backend(pid);
```

### Show SSL details

```sql
SELECT
name,
Expand All @@ -213,7 +238,9 @@ WHERE
OR category ILIKE '%SSL%'
OR short_desc ILIKE '%SSL%';
```

### Show resources

```sql
SELECT
name,
Expand All @@ -234,9 +261,17 @@ WHERE
category ILIKE '%Resource%';
```

## Miscelaneus SQL snipets

```sql
select count(1), foo, bar
from db_name
group by foo, bar
order by count(1) desc
```

## Links

[Database security requirements guide for Department of Defense](https://www.stigviewer.com/stig/database_security_requirements_guide/)

[Useful postgresql queries](https://codefibershq.com/blog/useful-postgresql-pgsql-queries-commands-and-snippets)
[Useful postgresql queries](https://codefibershq.com/blog/useful-postgresql-pgsql-queries-commands-and-snippets)
37 changes: 0 additions & 37 deletions content/Shell/Git-BashNotes.md

This file was deleted.

10 changes: 10 additions & 0 deletions content/Shell/Git_Tips.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,13 @@ Git config on Windows corporate machine with the WPAD Proxy and bandwidth restri
[http]
proxy = http://<user>:<passwd>@wpadweb.d<omain.org>/wpad.pac:3128 #8080
```

## Git-Bash on windows

Fix python path

```sh
cat /usr/bin/python
#!/bin/bash
"$ProgramW6432/Python3109/python" "${@}"
```
1 change: 0 additions & 1 deletion index.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ In no sense organized.
* [Deploy the program in one line](./content/Shell/Deploy-program-in-one-line.md)
* [Find And Xargs Tips](./content/Shell/FindAndXargsTips.md)
* [Git Tips](./content/Shell/Git_Tips.md)
* [Git-Bash Notes](./content/Shell/Git-BashNotes.md)
* [Miscelaneus Shell Links](./content/Shell/MiscelaneusShellLinks.md)
* [Notes on Miscelaneus Unix Utils](./content/Shell/NotesOnMiscUnixUtils.md)
* [Readline Key Bindings](./content/Shell/ReadlineKeyBindings.md)
Expand Down

0 comments on commit 1871a9e

Please sign in to comment.