Why use prime number $q$ such $q$| $(p-1)$ in discrete logarithm based schemes? In discrete logarithm based schemes on finite field we have a prime number $q$ that divides $p-1$ and $q$ is to specify a subgroup with the order $q$. But why do we do that? Why do not we work on the group with the order $p$ and need a subgroup with order $q$.
This is for security reasons (discrete logarithm calculation algorithms) or for computational optimization?
The group you're working with does not have order $p$. In discrete log schemes, you're not working in a finite field, $F_p$, but rather a multiplicative group $1,...,p-1$, which has order $p-1$. Since $p$ is a prime, $p-1$ is composite (as long as $p &gt; 3$). Group theory tells us that there is a subgroup of size $d$ for every $d$ that divides $p-1$.$^{1}$ By choosing a subgroup of order $q$, where $q$ is prime, we ensure that there are no (non-trivial) subgroups. This avoids small subgroup confinement attacks.

As mentioned in the other answer and comments, there are easy ways to find suitable $p$ and $q$. One is by using primes, $p$ and $q$, such that $p = 2q + 1$. Such a $p$ is called a safe prime. Another is by setting $p  = qr + 1$, where $r$ has (potentially) unknown factorization. The group generated by this $q$ is called a Schnorr group.

$^1$ This claim is not true in general. It is true for the group of a finite field. See this Wikipedia section Existence of subgroups of a given order for the gory details in the general case. This math.stackexchange answer is a nice proof for the group of a finite field.