a canonical transformation
A canonical transformation is a change of phase-space coordinates that keeps the machinery of Hamiltonian mechanics intact. In the Lagrangian world you may relabel positions however you like (any point transformation of the q's is fine). Hamiltonian mechanics is far more generous: because positions and momenta are on equal footing, you are allowed to mix them -- to build new coordinates that are blends of old positions and momenta -- as long as the new pair is still canonical. This freedom is the superpower of the formalism.
A transformation (q, p) -> (Q, P) is canonical if it preserves the form of Hamilton's equations, i.e. there exists a new Hamiltonian K(Q, P, t) with Q_dot = partial K / partial P and P_dot = - partial K / partial Q. Equivalently and more usefully, it is canonical if it preserves the fundamental Poisson brackets ({Q_i, P_j} = delta_ij, {Q_i, Q_j} = {P_i, P_j} = 0), or equivalently if it preserves the symplectic form sum dP ^ dQ = sum dp ^ dq. These conditions are all the same statement: the transformation's Jacobian is a symplectic matrix. Such transformations are generated by generating functions and automatically preserve phase-space volume (Liouville).
The point of all this freedom is to simplify a problem by choosing better coordinates. The dream is to transform to coordinates in which the new Hamiltonian is as simple as possible -- ideally zero, or a function of the new momenta alone. When K depends only on the new momenta, every new coordinate is cyclic and every new momentum is conserved, so the motion is trivial. Achieving this is precisely the program of Hamilton-Jacobi theory (aim for K = 0) and of action-angle variables (aim for K = H(P) alone).
The transformation Q = arctan(m omega q / p), P = (p^2 + m^2 omega^2 q^2)/(2 m omega) is canonical, and it turns the harmonic-oscillator Hamiltonian into K = omega P. Now Q is cyclic, so P (proportional to the energy) is conserved, and Q_dot = omega gives Q = omega t + const -- the oscillator solved in one line by choosing the right canonical coordinates.
A canonical transformation trivializes the harmonic oscillator: the new momentum is conserved and the new coordinate advances at constant rate omega.
Not every invertible change of (q, p) is canonical -- most are not. You must check the symplectic condition (equivalently, that the fundamental Poisson brackets are preserved). Rescaling q without a compensating rescaling of p, for instance, breaks {q, p} = 1 and is not canonical.